mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-31 02:10:37 +02:00
CodeMirror Plugin as a part of Monstra CMS
This commit is contained in:
674
plugins/codemirror/LICENSE
Normal file
674
plugins/codemirror/LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
4
plugins/codemirror/README.md
Normal file
4
plugins/codemirror/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
CodeMirror
|
||||
======================
|
||||
|
||||
CodeMirror is a versatile text editor implemented in JavaScript for the browser.
|
74
plugins/codemirror/codemirror.plugin.php
Normal file
74
plugins/codemirror/codemirror.plugin.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeMirror plugin
|
||||
*
|
||||
* @package Monstra
|
||||
* @subpackage Plugins
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012-2014 Romanenko Sergey / Awilum
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
// Register plugin
|
||||
Plugin::register( __FILE__,
|
||||
__('CodeMirror', 'codemirror'),
|
||||
__('CodeMirror is a versatile text editor implemented in JavaScript for the browser.', 'codemirror'),
|
||||
'1.0.0',
|
||||
'Awilum',
|
||||
'http://monstra.org/');
|
||||
|
||||
// Add hooks
|
||||
Action::add('admin_header', 'CodeMirror::headers');
|
||||
|
||||
/**
|
||||
* Codemirror Class
|
||||
*/
|
||||
class CodeMirror
|
||||
{
|
||||
|
||||
public static $theme = 'elegant';
|
||||
|
||||
/**
|
||||
* Set editor headers
|
||||
*/
|
||||
public static function headers()
|
||||
{
|
||||
echo ('
|
||||
<link rel="stylesheet" type="text/css" href="'.Option::get('siteurl').'/plugins/codemirror/codemirror/lib/codemirror.css" />
|
||||
<script type="text/javascript" src="'.Option::get('siteurl').'/plugins/codemirror/codemirror/lib/codemirror.js"></script>
|
||||
<script type="text/javascript" src="'.Option::get('siteurl').'/plugins/codemirror/codemirror/addon/edit/matchbrackets.js"></script>
|
||||
<script type="text/javascript" src="'.Option::get('siteurl').'/plugins/codemirror/codemirror/mode/htmlmixed/htmlmixed.js"></script>
|
||||
<script type="text/javascript" src="'.Option::get('siteurl').'/plugins/codemirror/codemirror/mode/xml/xml.js"></script>
|
||||
<script type="text/javascript" src="'.Option::get('siteurl').'/plugins/codemirror/codemirror/mode/javascript/javascript.js"></script>
|
||||
<script type="text/javascript" src="'.Option::get('siteurl').'/plugins/codemirror/codemirror/mode/php/php.js"></script>
|
||||
<link rel="stylesheet" href="'.Option::get('siteurl').'/plugins/codemirror/codemirror/theme/'.CodeMirror::$theme.'.css">
|
||||
<style>
|
||||
.CodeMirror {
|
||||
height:400px!important;
|
||||
border: 1px solid #ccc;
|
||||
color: #555;
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.428571429;
|
||||
}
|
||||
</style>
|
||||
');
|
||||
|
||||
if (Request::get('id') == 'themes' || Request::get('id') == 'snippets') {
|
||||
echo ('<script>
|
||||
$(document).ready(function() {
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("content"), {
|
||||
lineNumbers: false,
|
||||
matchBrackets: true,
|
||||
indentUnit: 4,
|
||||
mode: "htmlmixed",
|
||||
indentWithTabs: true,
|
||||
theme: "'.CodeMirror::$theme.'"
|
||||
});
|
||||
});
|
||||
</script>');
|
||||
}
|
||||
}
|
||||
}
|
8
plugins/codemirror/codemirror/.gitattributes
vendored
Normal file
8
plugins/codemirror/codemirror/.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
*.txt text
|
||||
*.js text
|
||||
*.html text
|
||||
*.md text
|
||||
*.json text
|
||||
*.yml text
|
||||
*.css text
|
||||
*.svg text
|
6
plugins/codemirror/codemirror/.gitignore
vendored
Normal file
6
plugins/codemirror/codemirror/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/node_modules
|
||||
/npm-debug.log
|
||||
test.html
|
||||
.tern-*
|
||||
*~
|
||||
*.swp
|
2
plugins/codemirror/codemirror/.htaccess
Normal file
2
plugins/codemirror/codemirror/.htaccess
Normal file
@@ -0,0 +1,2 @@
|
||||
Options -Indexes
|
||||
Allow from all
|
3
plugins/codemirror/codemirror/.travis.yml
Normal file
3
plugins/codemirror/codemirror/.travis.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
255
plugins/codemirror/codemirror/AUTHORS
Normal file
255
plugins/codemirror/codemirror/AUTHORS
Normal file
@@ -0,0 +1,255 @@
|
||||
List of CodeMirror contributors. Updated before every release.
|
||||
|
||||
4r2r
|
||||
Aaron Brooks
|
||||
Adam King
|
||||
adanlobato
|
||||
Adán Lobato
|
||||
aeroson
|
||||
Ahmad Amireh
|
||||
Ahmad M. Zawawi
|
||||
ahoward
|
||||
Akeksandr Motsjonov
|
||||
Albert Xing
|
||||
Alexander Pavlov
|
||||
Alexander Schepanovski
|
||||
alexey-k
|
||||
Alex Piggott
|
||||
Amy
|
||||
Ananya Sen
|
||||
AndersMad
|
||||
Andre von Houck
|
||||
Andrey Lushnikov
|
||||
Andy Kimball
|
||||
Andy Li
|
||||
angelozerr
|
||||
angelo.zerr@gmail.com
|
||||
Ankit Ahuja
|
||||
Ansel Santosa
|
||||
Anthony Grimes
|
||||
areos
|
||||
Atul Bhouraskar
|
||||
Aurelian Oancea
|
||||
Bastian Müller
|
||||
benbro
|
||||
Benjamin DeCoste
|
||||
Ben Keen
|
||||
boomyjee
|
||||
borawjm
|
||||
Brandon Frohs
|
||||
Brett Zamir
|
||||
Brian Sletten
|
||||
Bruce Mitchener
|
||||
Chandra Sekhar Pydi
|
||||
Charles Skelton
|
||||
Chris Coyier
|
||||
Chris Granger
|
||||
Chris Morgan
|
||||
Christopher Brown
|
||||
ciaranj
|
||||
CodeAnimal
|
||||
ComFreek
|
||||
dagsta
|
||||
Dan Heberden
|
||||
Daniel, Dao Quang Minh
|
||||
Daniel Faust
|
||||
Daniel Huigens
|
||||
Daniel Neel
|
||||
Daniel Parnell
|
||||
Danny Yoo
|
||||
David Mignot
|
||||
David Pathakjee
|
||||
deebugger
|
||||
Deep Thought
|
||||
Dominator008
|
||||
Domizio Demichelis
|
||||
Drew Bratcher
|
||||
Drew Hintz
|
||||
Drew Khoury
|
||||
Dror BG
|
||||
duralog
|
||||
edsharp
|
||||
ekhaled
|
||||
Eric Allam
|
||||
eustas
|
||||
Fauntleroy
|
||||
fbuchinger
|
||||
feizhang365
|
||||
Felipe Lalanne
|
||||
Felix Raab
|
||||
Filip Noetzel
|
||||
flack
|
||||
ForbesLindesay
|
||||
Ford_Lawnmower
|
||||
Gabriel Nahmias
|
||||
galambalazs
|
||||
Gautam Mehta
|
||||
Glenn Jorde
|
||||
Glenn Ruehle
|
||||
Golevka
|
||||
Gordon Smith
|
||||
greengiant
|
||||
Guillaume Massé
|
||||
Guillaume Massé
|
||||
Hans Engel
|
||||
Hardest
|
||||
Hasan Karahan
|
||||
Hocdoc
|
||||
Ian Beck
|
||||
Ian Wehrman
|
||||
Ian Wetherbee
|
||||
Ice White
|
||||
ICHIKAWA, Yuji
|
||||
Ingo Richter
|
||||
Irakli Gozalishvili
|
||||
Ivan Kurnosov
|
||||
Jacob Lee
|
||||
Jakub Vrana
|
||||
James Campos
|
||||
James Thorne
|
||||
Jamie Hill
|
||||
Jan Jongboom
|
||||
jankeromnes
|
||||
Jan Keromnes
|
||||
Jan T. Sott
|
||||
Jason
|
||||
Jason Grout
|
||||
Jason Johnston
|
||||
Jason San Jose
|
||||
Jason Siefken
|
||||
Jean Boussier
|
||||
jeffkenton
|
||||
Jeff Pickhardt
|
||||
jem (graphite)
|
||||
Jochen Berger
|
||||
John Connor
|
||||
John Lees-Miller
|
||||
John Snelson
|
||||
jongalloway
|
||||
Joost-Wim Boekesteijn
|
||||
Joseph Pecoraro
|
||||
Joshua Newman
|
||||
jots
|
||||
Juan Benavides Romero
|
||||
Jucovschi Constantin
|
||||
jwallers@gmail.com
|
||||
kaniga
|
||||
Ken Newman
|
||||
Ken Rockot
|
||||
Kevin Sawicki
|
||||
Klaus Silveira
|
||||
Koh Zi Han, Cliff
|
||||
komakino
|
||||
Konstantin Lopuhin
|
||||
koops
|
||||
ks-ifware
|
||||
kubelsmieci
|
||||
Lanny
|
||||
leaf corcoran
|
||||
Leonya Khachaturov
|
||||
Liam Newman
|
||||
LM
|
||||
Lorenzo Stoakes
|
||||
lynschinzer
|
||||
Maksim Lin
|
||||
Maksym Taran
|
||||
Marat Dreizin
|
||||
Marco Aurélio
|
||||
Marijn Haverbeke
|
||||
Mario Pietsch
|
||||
Mark Lentczner
|
||||
Martin Balek
|
||||
Martín Gaitán
|
||||
Mason Malone
|
||||
Mateusz Paprocki
|
||||
mats cronqvist
|
||||
Matthew Beale
|
||||
Matthias BUSSONNIER
|
||||
Matt McDonald
|
||||
Matt Pass
|
||||
Matt Sacks
|
||||
Maximilian Hils
|
||||
Max Kirsch
|
||||
mbarkhau
|
||||
Metatheos
|
||||
Micah Dubinko
|
||||
Michael Lehenbauer
|
||||
Michael Zhou
|
||||
Mighty Guava
|
||||
Miguel Castillo
|
||||
Mike
|
||||
Mike Brevoort
|
||||
Mike Diaz
|
||||
Mike Ivanov
|
||||
Mike Kadin
|
||||
MinRK
|
||||
misfo
|
||||
mps
|
||||
Narciso Jaramillo
|
||||
Nathan Williams
|
||||
nerbert
|
||||
nguillaumin
|
||||
Niels van Groningen
|
||||
Nikita Beloglazov
|
||||
Nikita Vasilyev
|
||||
nlwillia
|
||||
pablo
|
||||
Page
|
||||
Patrick Strawderman
|
||||
Paul Garvin
|
||||
Paul Ivanov
|
||||
Pavel Feldman
|
||||
Paweł Bartkiewicz
|
||||
peteguhl
|
||||
peterkroon
|
||||
Peter Kroon
|
||||
prasanthj
|
||||
Prasanth J
|
||||
Rahul
|
||||
Randy Edmunds
|
||||
Richard Z.H. Wang
|
||||
robertop23
|
||||
Robert Plummer
|
||||
Ruslan Osmanov
|
||||
sabaca
|
||||
Samuel Ainsworth
|
||||
sandeepshetty
|
||||
santec
|
||||
Sascha Peilicke
|
||||
satchmorun
|
||||
sathyamoorthi
|
||||
SCLINIC\jdecker
|
||||
shaund
|
||||
shaun gilchrist
|
||||
Shmuel Englard
|
||||
sonson
|
||||
spastorelli
|
||||
Stas Kobzar
|
||||
Stefan Borsje
|
||||
Steffen Beyer
|
||||
Steve O'Hara
|
||||
stoskov
|
||||
Tarmil
|
||||
tfjgeorge
|
||||
Thaddee Tyl
|
||||
think
|
||||
Thomas Dvornik
|
||||
Thomas Schmid
|
||||
Tim Baumann
|
||||
Timothy Farrell
|
||||
Timothy Hatcher
|
||||
TobiasBg
|
||||
Tomas-A
|
||||
Tomas Varaneckas
|
||||
Tom Erik Støwer
|
||||
Tom MacWright
|
||||
Tony Jian
|
||||
Vestimir Markov
|
||||
vf
|
||||
Volker Mische
|
||||
William Jamieson
|
||||
Wojtek Ptak
|
||||
Xavier Mendez
|
||||
Yunchi Luo
|
||||
Yuvi Panda
|
||||
Zachary Dremann
|
72
plugins/codemirror/codemirror/CONTRIBUTING.md
Normal file
72
plugins/codemirror/codemirror/CONTRIBUTING.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# How to contribute
|
||||
|
||||
- [Getting help](#getting-help-)
|
||||
- [Submitting bug reports](#submitting-bug-reports-)
|
||||
- [Contributing code](#contributing-code-)
|
||||
|
||||
## Getting help
|
||||
|
||||
Community discussion, questions, and informal bug reporting is done on the
|
||||
[CodeMirror Google group](http://groups.google.com/group/codemirror).
|
||||
|
||||
## Submitting bug reports
|
||||
|
||||
The preferred way to report bugs is to use the
|
||||
[GitHub issue tracker](http://github.com/marijnh/CodeMirror/issues). Before
|
||||
reporting a bug, read these pointers.
|
||||
|
||||
**Note:** The issue tracker is for *bugs*, not requests for help. Questions
|
||||
should be asked on the
|
||||
[CodeMirror Google group](http://groups.google.com/group/codemirror) instead.
|
||||
|
||||
### Reporting bugs effectively
|
||||
|
||||
- CodeMirror is maintained by volunteers. They don't owe you anything, so be
|
||||
polite. Reports with an indignant or belligerent tone tend to be moved to the
|
||||
bottom of the pile.
|
||||
|
||||
- Include information about **the browser in which the problem occurred**. Even
|
||||
if you tested several browsers, and the problem occurred in all of them,
|
||||
mention this fact in the bug report. Also include browser version numbers and
|
||||
the operating system that you're on.
|
||||
|
||||
- Mention which release of CodeMirror you're using. Preferably, try also with
|
||||
the current development snapshot, to ensure the problem has not already been
|
||||
fixed.
|
||||
|
||||
- Mention very precisely what went wrong. "X is broken" is not a good bug
|
||||
report. What did you expect to happen? What happened instead? Describe the
|
||||
exact steps a maintainer has to take to make the problem occur. We can not
|
||||
fix something that we can not observe.
|
||||
|
||||
- If the problem can not be reproduced in any of the demos included in the
|
||||
CodeMirror distribution, please provide an HTML document that demonstrates
|
||||
the problem. The best way to do this is to go to
|
||||
[jsbin.com](http://jsbin.com/ihunin/edit), enter it there, press save, and
|
||||
include the resulting link in your bug report.
|
||||
|
||||
## Contributing code
|
||||
|
||||
- Make sure you have a [GitHub Account](https://github.com/signup/free)
|
||||
- Fork [CodeMirror](https://github.com/marijnh/CodeMirror/)
|
||||
([how to fork a repo](https://help.github.com/articles/fork-a-repo))
|
||||
- Make your changes
|
||||
- If your changes are easy to test or likely to regress, add tests.
|
||||
Tests for the core go into `test/test.js`, some modes have their own
|
||||
test suite under `mode/XXX/test.js`. Feel free to add new test
|
||||
suites to modes that don't have one yet (be sure to link the new
|
||||
tests into `test/index.html`).
|
||||
- Follow the general code style of the rest of the project (see
|
||||
below). Run `bin/lint` to verify that the linter is happy.
|
||||
- Make sure all tests pass. Visit `test/index.html` in your browser to
|
||||
run them.
|
||||
- Submit a pull request
|
||||
([how to create a pull request](https://help.github.com/articles/fork-a-repo))
|
||||
|
||||
### Coding standards
|
||||
|
||||
- 2 spaces per indentation level, no tabs.
|
||||
- Include semicolons after statements.
|
||||
- Note that the linter (`bin/lint`) which is run after each commit
|
||||
complains about unused variables and functions. Prefix their names
|
||||
with an underscore to muffle it.
|
19
plugins/codemirror/codemirror/LICENSE
Normal file
19
plugins/codemirror/codemirror/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (C) 2013 by Marijn Haverbeke <marijnh@gmail.com> and others
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
11
plugins/codemirror/codemirror/README.md
Normal file
11
plugins/codemirror/codemirror/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# CodeMirror
|
||||
[](http://travis-ci.org/marijnh/CodeMirror)
|
||||
[](http://badge.fury.io/js/codemirror)
|
||||
|
||||
CodeMirror is a JavaScript component that provides a code editor in
|
||||
the browser. When a mode is available for the language you are coding
|
||||
in, it will color your code, and optionally help with indentation.
|
||||
|
||||
The project page is http://codemirror.net
|
||||
The manual is at http://codemirror.net/doc/manual.html
|
||||
The contributing guidelines are in [CONTRIBUTING.md](https://github.com/marijnh/CodeMirror/blob/master/CONTRIBUTING.md)
|
145
plugins/codemirror/codemirror/addon/comment/comment.js
vendored
Normal file
145
plugins/codemirror/codemirror/addon/comment/comment.js
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var noOptions = {};
|
||||
var nonWS = /[^\s\u00a0]/;
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function firstNonWS(str) {
|
||||
var found = str.search(nonWS);
|
||||
return found == -1 ? 0 : found;
|
||||
}
|
||||
|
||||
CodeMirror.commands.toggleComment = function(cm) {
|
||||
var from = cm.getCursor("start"), to = cm.getCursor("end");
|
||||
cm.uncomment(from, to) || cm.lineComment(from, to);
|
||||
};
|
||||
|
||||
CodeMirror.defineExtension("lineComment", function(from, to, options) {
|
||||
if (!options) options = noOptions;
|
||||
var self = this, mode = self.getModeAt(from);
|
||||
var commentString = options.lineComment || mode.lineComment;
|
||||
if (!commentString) {
|
||||
if (options.blockCommentStart || mode.blockCommentStart) {
|
||||
options.fullLines = true;
|
||||
self.blockComment(from, to, options);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var firstLine = self.getLine(from.line);
|
||||
if (firstLine == null) return;
|
||||
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
|
||||
var pad = options.padding == null ? " " : options.padding;
|
||||
var blankLines = options.commentBlankLines || from.line == to.line;
|
||||
|
||||
self.operation(function() {
|
||||
if (options.indent) {
|
||||
var baseString = firstLine.slice(0, firstNonWS(firstLine));
|
||||
for (var i = from.line; i < end; ++i) {
|
||||
var line = self.getLine(i), cut = baseString.length;
|
||||
if (!blankLines && !nonWS.test(line)) continue;
|
||||
if (line.slice(0, cut) != baseString) cut = firstNonWS(line);
|
||||
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut));
|
||||
}
|
||||
} else {
|
||||
for (var i = from.line; i < end; ++i) {
|
||||
if (blankLines || nonWS.test(self.getLine(i)))
|
||||
self.replaceRange(commentString + pad, Pos(i, 0));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("blockComment", function(from, to, options) {
|
||||
if (!options) options = noOptions;
|
||||
var self = this, mode = self.getModeAt(from);
|
||||
var startString = options.blockCommentStart || mode.blockCommentStart;
|
||||
var endString = options.blockCommentEnd || mode.blockCommentEnd;
|
||||
if (!startString || !endString) {
|
||||
if ((options.lineComment || mode.lineComment) && options.fullLines != false)
|
||||
self.lineComment(from, to, options);
|
||||
return;
|
||||
}
|
||||
|
||||
var end = Math.min(to.line, self.lastLine());
|
||||
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
|
||||
|
||||
var pad = options.padding == null ? " " : options.padding;
|
||||
if (from.line > end) return;
|
||||
|
||||
self.operation(function() {
|
||||
if (options.fullLines != false) {
|
||||
var lastLineHasText = nonWS.test(self.getLine(end));
|
||||
self.replaceRange(pad + endString, Pos(end));
|
||||
self.replaceRange(startString + pad, Pos(from.line, 0));
|
||||
var lead = options.blockCommentLead || mode.blockCommentLead;
|
||||
if (lead != null) for (var i = from.line + 1; i <= end; ++i)
|
||||
if (i != end || lastLineHasText)
|
||||
self.replaceRange(lead + pad, Pos(i, 0));
|
||||
} else {
|
||||
self.replaceRange(endString, to);
|
||||
self.replaceRange(startString, from);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("uncomment", function(from, to, options) {
|
||||
if (!options) options = noOptions;
|
||||
var self = this, mode = self.getModeAt(from);
|
||||
var end = Math.min(to.line, self.lastLine()), start = Math.min(from.line, end);
|
||||
|
||||
// Try finding line comments
|
||||
var lineString = options.lineComment || mode.lineComment, lines = [];
|
||||
var pad = options.padding == null ? " " : options.padding, didSomething;
|
||||
lineComment: {
|
||||
if (!lineString) break lineComment;
|
||||
for (var i = start; i <= end; ++i) {
|
||||
var line = self.getLine(i);
|
||||
var found = line.indexOf(lineString);
|
||||
if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment;
|
||||
if (i != start && found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
|
||||
lines.push(line);
|
||||
}
|
||||
self.operation(function() {
|
||||
for (var i = start; i <= end; ++i) {
|
||||
var line = lines[i - start];
|
||||
var pos = line.indexOf(lineString), endPos = pos + lineString.length;
|
||||
if (pos < 0) continue;
|
||||
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length;
|
||||
didSomething = true;
|
||||
self.replaceRange("", Pos(i, pos), Pos(i, endPos));
|
||||
}
|
||||
});
|
||||
if (didSomething) return true;
|
||||
}
|
||||
|
||||
// Try block comments
|
||||
var startString = options.blockCommentStart || mode.blockCommentStart;
|
||||
var endString = options.blockCommentEnd || mode.blockCommentEnd;
|
||||
if (!startString || !endString) return false;
|
||||
var lead = options.blockCommentLead || mode.blockCommentLead;
|
||||
var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end);
|
||||
var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString);
|
||||
if (close == -1 && start != end) {
|
||||
endLine = self.getLine(--end);
|
||||
close = endLine.lastIndexOf(endString);
|
||||
}
|
||||
if (open == -1 || close == -1) return false;
|
||||
|
||||
self.operation(function() {
|
||||
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)),
|
||||
Pos(end, close + endString.length));
|
||||
var openEnd = open + startString.length;
|
||||
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length;
|
||||
self.replaceRange("", Pos(start, open), Pos(start, openEnd));
|
||||
if (lead) for (var i = start + 1; i <= end; ++i) {
|
||||
var line = self.getLine(i), found = line.indexOf(lead);
|
||||
if (found == -1 || nonWS.test(line.slice(0, found))) continue;
|
||||
var foundEnd = found + lead.length;
|
||||
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length;
|
||||
self.replaceRange("", Pos(i, found), Pos(i, foundEnd));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
});
|
||||
})();
|
54
plugins/codemirror/codemirror/addon/comment/continuecomment.js
vendored
Normal file
54
plugins/codemirror/codemirror/addon/comment/continuecomment.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
(function() {
|
||||
var modes = ["clike", "css", "javascript"];
|
||||
for (var i = 0; i < modes.length; ++i)
|
||||
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
|
||||
|
||||
function continueComment(cm) {
|
||||
var pos = cm.getCursor(), token = cm.getTokenAt(pos);
|
||||
if (token.type != "comment") return CodeMirror.Pass;
|
||||
var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
|
||||
|
||||
var insert;
|
||||
if (mode.blockCommentStart && mode.blockCommentContinue) {
|
||||
var end = token.string.indexOf(mode.blockCommentEnd);
|
||||
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
|
||||
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length) {
|
||||
// Comment ended, don't continue it
|
||||
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
|
||||
insert = full.slice(0, token.start);
|
||||
if (!/^\s*$/.test(insert)) {
|
||||
insert = "";
|
||||
for (var i = 0; i < token.start; ++i) insert += " ";
|
||||
}
|
||||
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
|
||||
found + mode.blockCommentContinue.length > token.start &&
|
||||
/^\s*$/.test(full.slice(0, found))) {
|
||||
insert = full.slice(0, found);
|
||||
}
|
||||
if (insert != null) insert += mode.blockCommentContinue;
|
||||
}
|
||||
if (insert == null && mode.lineComment) {
|
||||
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
|
||||
if (found > -1) {
|
||||
insert = line.slice(0, found);
|
||||
if (/\S/.test(insert)) insert = null;
|
||||
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (insert != null)
|
||||
cm.replaceSelection("\n" + insert, "end");
|
||||
else
|
||||
return CodeMirror.Pass;
|
||||
}
|
||||
|
||||
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
|
||||
if (prev && prev != CodeMirror.Init)
|
||||
cm.removeKeyMap("continueComment");
|
||||
if (val) {
|
||||
var map = {name: "continueComment"};
|
||||
map[typeof val == "string" ? val : "Enter"] = continueComment;
|
||||
cm.addKeyMap(map);
|
||||
}
|
||||
});
|
||||
})();
|
32
plugins/codemirror/codemirror/addon/dialog/dialog.css
vendored
Normal file
32
plugins/codemirror/codemirror/addon/dialog/dialog.css
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
.CodeMirror-dialog {
|
||||
position: absolute;
|
||||
left: 0; right: 0;
|
||||
background: white;
|
||||
z-index: 15;
|
||||
padding: .1em .8em;
|
||||
overflow: hidden;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.CodeMirror-dialog-top {
|
||||
border-bottom: 1px solid #eee;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.CodeMirror-dialog-bottom {
|
||||
border-top: 1px solid #eee;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.CodeMirror-dialog input {
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
width: 20em;
|
||||
color: inherit;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.CodeMirror-dialog button {
|
||||
font-size: 70%;
|
||||
}
|
121
plugins/codemirror/codemirror/addon/dialog/dialog.js
vendored
Normal file
121
plugins/codemirror/codemirror/addon/dialog/dialog.js
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
// Open simple dialogs on top of an editor. Relies on dialog.css.
|
||||
|
||||
(function() {
|
||||
function dialogDiv(cm, template, bottom) {
|
||||
var wrap = cm.getWrapperElement();
|
||||
var dialog;
|
||||
dialog = wrap.appendChild(document.createElement("div"));
|
||||
if (bottom) {
|
||||
dialog.className = "CodeMirror-dialog CodeMirror-dialog-bottom";
|
||||
} else {
|
||||
dialog.className = "CodeMirror-dialog CodeMirror-dialog-top";
|
||||
}
|
||||
if (typeof template == "string") {
|
||||
dialog.innerHTML = template;
|
||||
} else { // Assuming it's a detached DOM element.
|
||||
dialog.appendChild(template);
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
function closeNotification(cm, newVal) {
|
||||
if (cm.state.currentNotificationClose)
|
||||
cm.state.currentNotificationClose();
|
||||
cm.state.currentNotificationClose = newVal;
|
||||
}
|
||||
|
||||
CodeMirror.defineExtension("openDialog", function(template, callback, options) {
|
||||
closeNotification(this, null);
|
||||
var dialog = dialogDiv(this, template, options && options.bottom);
|
||||
var closed = false, me = this;
|
||||
function close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
dialog.parentNode.removeChild(dialog);
|
||||
}
|
||||
var inp = dialog.getElementsByTagName("input")[0], button;
|
||||
if (inp) {
|
||||
CodeMirror.on(inp, "keydown", function(e) {
|
||||
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
|
||||
if (e.keyCode == 13 || e.keyCode == 27) {
|
||||
CodeMirror.e_stop(e);
|
||||
close();
|
||||
me.focus();
|
||||
if (e.keyCode == 13) callback(inp.value);
|
||||
}
|
||||
});
|
||||
if (options && options.onKeyUp) {
|
||||
CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
|
||||
}
|
||||
if (options && options.value) inp.value = options.value;
|
||||
inp.focus();
|
||||
CodeMirror.on(inp, "blur", close);
|
||||
} else if (button = dialog.getElementsByTagName("button")[0]) {
|
||||
CodeMirror.on(button, "click", function() {
|
||||
close();
|
||||
me.focus();
|
||||
});
|
||||
button.focus();
|
||||
CodeMirror.on(button, "blur", close);
|
||||
}
|
||||
return close;
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) {
|
||||
closeNotification(this, null);
|
||||
var dialog = dialogDiv(this, template, options && options.bottom);
|
||||
var buttons = dialog.getElementsByTagName("button");
|
||||
var closed = false, me = this, blurring = 1;
|
||||
function close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
dialog.parentNode.removeChild(dialog);
|
||||
me.focus();
|
||||
}
|
||||
buttons[0].focus();
|
||||
for (var i = 0; i < buttons.length; ++i) {
|
||||
var b = buttons[i];
|
||||
(function(callback) {
|
||||
CodeMirror.on(b, "click", function(e) {
|
||||
CodeMirror.e_preventDefault(e);
|
||||
close();
|
||||
if (callback) callback(me);
|
||||
});
|
||||
})(callbacks[i]);
|
||||
CodeMirror.on(b, "blur", function() {
|
||||
--blurring;
|
||||
setTimeout(function() { if (blurring <= 0) close(); }, 200);
|
||||
});
|
||||
CodeMirror.on(b, "focus", function() { ++blurring; });
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* openNotification
|
||||
* Opens a notification, that can be closed with an optional timer
|
||||
* (default 5000ms timer) and always closes on click.
|
||||
*
|
||||
* If a notification is opened while another is opened, it will close the
|
||||
* currently opened one and open the new one immediately.
|
||||
*/
|
||||
CodeMirror.defineExtension("openNotification", function(template, options) {
|
||||
closeNotification(this, close);
|
||||
var dialog = dialogDiv(this, template, options && options.bottom);
|
||||
var duration = options && (options.duration === undefined ? 5000 : options.duration);
|
||||
var closed = false, doneTimer;
|
||||
|
||||
function close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
clearTimeout(doneTimer);
|
||||
dialog.parentNode.removeChild(dialog);
|
||||
}
|
||||
|
||||
CodeMirror.on(dialog, 'click', function(e) {
|
||||
CodeMirror.e_preventDefault(e);
|
||||
close();
|
||||
});
|
||||
if (duration)
|
||||
doneTimer = setTimeout(close, options.duration);
|
||||
});
|
||||
})();
|
6
plugins/codemirror/codemirror/addon/display/fullscreen.css
vendored
Normal file
6
plugins/codemirror/codemirror/addon/display/fullscreen.css
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
.CodeMirror-fullscreen {
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
height: auto;
|
||||
z-index: 9;
|
||||
}
|
31
plugins/codemirror/codemirror/addon/display/fullscreen.js
vendored
Normal file
31
plugins/codemirror/codemirror/addon/display/fullscreen.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
|
||||
if (old == CodeMirror.Init) old = false;
|
||||
if (!old == !val) return;
|
||||
if (val) setFullscreen(cm);
|
||||
else setNormal(cm);
|
||||
});
|
||||
|
||||
function setFullscreen(cm) {
|
||||
var wrap = cm.getWrapperElement();
|
||||
cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
|
||||
width: wrap.style.width, height: wrap.style.height};
|
||||
wrap.style.width = "";
|
||||
wrap.style.height = "auto";
|
||||
wrap.className += " CodeMirror-fullscreen";
|
||||
document.documentElement.style.overflow = "hidden";
|
||||
cm.refresh();
|
||||
}
|
||||
|
||||
function setNormal(cm) {
|
||||
var wrap = cm.getWrapperElement();
|
||||
wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
|
||||
document.documentElement.style.overflow = "";
|
||||
var info = cm.state.fullScreenRestore;
|
||||
wrap.style.width = info.width; wrap.style.height = info.height;
|
||||
window.scrollTo(info.scrollLeft, info.scrollTop);
|
||||
cm.refresh();
|
||||
}
|
||||
})();
|
48
plugins/codemirror/codemirror/addon/display/placeholder.js
vendored
Normal file
48
plugins/codemirror/codemirror/addon/display/placeholder.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
(function() {
|
||||
CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
|
||||
var prev = old && old != CodeMirror.Init;
|
||||
if (val && !prev) {
|
||||
cm.on("blur", onBlur);
|
||||
cm.on("change", onChange);
|
||||
onChange(cm);
|
||||
} else if (!val && prev) {
|
||||
cm.off("blur", onBlur);
|
||||
cm.off("change", onChange);
|
||||
clearPlaceholder(cm);
|
||||
var wrapper = cm.getWrapperElement();
|
||||
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
|
||||
}
|
||||
|
||||
if (val && !cm.hasFocus()) onBlur(cm);
|
||||
});
|
||||
|
||||
function clearPlaceholder(cm) {
|
||||
if (cm.state.placeholder) {
|
||||
cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
|
||||
cm.state.placeholder = null;
|
||||
}
|
||||
}
|
||||
function setPlaceholder(cm) {
|
||||
clearPlaceholder(cm);
|
||||
var elt = cm.state.placeholder = document.createElement("pre");
|
||||
elt.style.cssText = "height: 0; overflow: visible";
|
||||
elt.className = "CodeMirror-placeholder";
|
||||
elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
|
||||
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
|
||||
}
|
||||
|
||||
function onBlur(cm) {
|
||||
if (isEmpty(cm)) setPlaceholder(cm);
|
||||
}
|
||||
function onChange(cm) {
|
||||
var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
|
||||
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
|
||||
|
||||
if (empty) setPlaceholder(cm);
|
||||
else clearPlaceholder(cm);
|
||||
}
|
||||
|
||||
function isEmpty(cm) {
|
||||
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
|
||||
}
|
||||
})();
|
82
plugins/codemirror/codemirror/addon/edit/closebrackets.js
vendored
Normal file
82
plugins/codemirror/codemirror/addon/edit/closebrackets.js
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
(function() {
|
||||
var DEFAULT_BRACKETS = "()[]{}''\"\"";
|
||||
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
|
||||
var SPACE_CHAR_REGEX = /\s/;
|
||||
|
||||
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
||||
if (old != CodeMirror.Init && old)
|
||||
cm.removeKeyMap("autoCloseBrackets");
|
||||
if (!val) return;
|
||||
var pairs = DEFAULT_BRACKETS, explode = DEFAULT_EXPLODE_ON_ENTER;
|
||||
if (typeof val == "string") pairs = val;
|
||||
else if (typeof val == "object") {
|
||||
if (val.pairs != null) pairs = val.pairs;
|
||||
if (val.explode != null) explode = val.explode;
|
||||
}
|
||||
var map = buildKeymap(pairs);
|
||||
if (explode) map.Enter = buildExplodeHandler(explode);
|
||||
cm.addKeyMap(map);
|
||||
});
|
||||
|
||||
function charsAround(cm, pos) {
|
||||
var str = cm.getRange(CodeMirror.Pos(pos.line, pos.ch - 1),
|
||||
CodeMirror.Pos(pos.line, pos.ch + 1));
|
||||
return str.length == 2 ? str : null;
|
||||
}
|
||||
|
||||
function buildKeymap(pairs) {
|
||||
var map = {
|
||||
name : "autoCloseBrackets",
|
||||
Backspace: function(cm) {
|
||||
if (cm.somethingSelected()) return CodeMirror.Pass;
|
||||
var cur = cm.getCursor(), around = charsAround(cm, cur);
|
||||
if (around && pairs.indexOf(around) % 2 == 0)
|
||||
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
|
||||
else
|
||||
return CodeMirror.Pass;
|
||||
}
|
||||
};
|
||||
var closingBrackets = "";
|
||||
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
|
||||
if (left != right) closingBrackets += right;
|
||||
function surround(cm) {
|
||||
var selection = cm.getSelection();
|
||||
cm.replaceSelection(left + selection + right);
|
||||
}
|
||||
function maybeOverwrite(cm) {
|
||||
var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
|
||||
if (ahead != right || cm.somethingSelected()) return CodeMirror.Pass;
|
||||
else cm.execCommand("goCharRight");
|
||||
}
|
||||
map["'" + left + "'"] = function(cm) {
|
||||
if (left == "'" && cm.getTokenAt(cm.getCursor()).type == "comment")
|
||||
return CodeMirror.Pass;
|
||||
if (cm.somethingSelected()) return surround(cm);
|
||||
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
|
||||
var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
|
||||
var line = cm.getLine(cur.line), nextChar = line.charAt(cur.ch), curChar = cur.ch > 0 ? line.charAt(cur.ch - 1) : "";
|
||||
if (left == right && CodeMirror.isWordChar(curChar))
|
||||
return CodeMirror.Pass;
|
||||
if (line.length == cur.ch || closingBrackets.indexOf(nextChar) >= 0 || SPACE_CHAR_REGEX.test(nextChar))
|
||||
cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
|
||||
else
|
||||
return CodeMirror.Pass;
|
||||
};
|
||||
if (left != right) map["'" + right + "'"] = maybeOverwrite;
|
||||
})(pairs.charAt(i), pairs.charAt(i + 1));
|
||||
return map;
|
||||
}
|
||||
|
||||
function buildExplodeHandler(pairs) {
|
||||
return function(cm) {
|
||||
var cur = cm.getCursor(), around = charsAround(cm, cur);
|
||||
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
||||
cm.operation(function() {
|
||||
var newPos = CodeMirror.Pos(cur.line + 1, 0);
|
||||
cm.replaceSelection("\n\n", {anchor: newPos, head: newPos}, "+input");
|
||||
cm.indentLine(cur.line + 1, null, true);
|
||||
cm.indentLine(cur.line + 2, null, true);
|
||||
});
|
||||
};
|
||||
}
|
||||
})();
|
89
plugins/codemirror/codemirror/addon/edit/closetag.js
vendored
Normal file
89
plugins/codemirror/codemirror/addon/edit/closetag.js
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Tag-closer extension for CodeMirror.
|
||||
*
|
||||
* This extension adds an "autoCloseTags" option that can be set to
|
||||
* either true to get the default behavior, or an object to further
|
||||
* configure its behavior.
|
||||
*
|
||||
* These are supported options:
|
||||
*
|
||||
* `whenClosing` (default true)
|
||||
* Whether to autoclose when the '/' of a closing tag is typed.
|
||||
* `whenOpening` (default true)
|
||||
* Whether to autoclose the tag when the final '>' of an opening
|
||||
* tag is typed.
|
||||
* `dontCloseTags` (default is empty tags for HTML, none for XML)
|
||||
* An array of tag names that should not be autoclosed.
|
||||
* `indentTags` (default is block tags for HTML, none for XML)
|
||||
* An array of tag names that should, when opened, cause a
|
||||
* blank line to be added inside the tag, and the blank line and
|
||||
* closing line to be indented.
|
||||
*
|
||||
* See demos/closetag.html for a usage example.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
|
||||
if (old != CodeMirror.Init && old)
|
||||
cm.removeKeyMap("autoCloseTags");
|
||||
if (!val) return;
|
||||
var map = {name: "autoCloseTags"};
|
||||
if (typeof val != "object" || val.whenClosing)
|
||||
map["'/'"] = function(cm) { return autoCloseSlash(cm); };
|
||||
if (typeof val != "object" || val.whenOpening)
|
||||
map["'>'"] = function(cm) { return autoCloseGT(cm); };
|
||||
cm.addKeyMap(map);
|
||||
});
|
||||
|
||||
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
|
||||
"source", "track", "wbr"];
|
||||
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
|
||||
"h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
|
||||
|
||||
function autoCloseGT(cm) {
|
||||
var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
||||
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
|
||||
|
||||
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
|
||||
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
|
||||
var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
|
||||
|
||||
var tagName = state.tagName;
|
||||
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
|
||||
var lowerTagName = tagName.toLowerCase();
|
||||
// Don't process the '>' at the end of an end-tag or self-closing tag
|
||||
if (tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
|
||||
tok.type == "tag" && state.type == "closeTag" ||
|
||||
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
|
||||
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1)
|
||||
return CodeMirror.Pass;
|
||||
|
||||
var doIndent = indentTags && indexOf(indentTags, lowerTagName) > -1;
|
||||
var curPos = doIndent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1);
|
||||
cm.replaceSelection(">" + (doIndent ? "\n\n" : "") + "</" + tagName + ">",
|
||||
{head: curPos, anchor: curPos});
|
||||
if (doIndent) {
|
||||
cm.indentLine(pos.line + 1);
|
||||
cm.indentLine(pos.line + 2);
|
||||
}
|
||||
}
|
||||
|
||||
function autoCloseSlash(cm) {
|
||||
var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
||||
if (tok.type == "string" || tok.string.charAt(0) != "<" ||
|
||||
tok.start != pos.ch - 1 || inner.mode.name != "xml")
|
||||
return CodeMirror.Pass;
|
||||
|
||||
var tagName = state.context && state.context.tagName;
|
||||
if (tagName) cm.replaceSelection("/" + tagName + ">", "end");
|
||||
}
|
||||
|
||||
function indexOf(collection, elt) {
|
||||
if (collection.indexOf) return collection.indexOf(elt);
|
||||
for (var i = 0, e = collection.length; i < e; ++i)
|
||||
if (collection[i] == elt) return i;
|
||||
return -1;
|
||||
}
|
||||
})();
|
25
plugins/codemirror/codemirror/addon/edit/continuelist.js
vendored
Normal file
25
plugins/codemirror/codemirror/addon/edit/continuelist.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
|
||||
unorderedBullets = '*+-';
|
||||
|
||||
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
|
||||
var pos = cm.getCursor(),
|
||||
inList = cm.getStateAfter(pos.line).list !== false,
|
||||
match;
|
||||
|
||||
if (!inList || !(match = cm.getLine(pos.line).match(listRE))) {
|
||||
cm.execCommand('newlineAndIndent');
|
||||
return;
|
||||
}
|
||||
|
||||
var indent = match[1], after = match[4];
|
||||
var bullet = unorderedBullets.indexOf(match[2]) >= 0
|
||||
? match[2]
|
||||
: (parseInt(match[3], 10) + 1) + '.';
|
||||
|
||||
cm.replaceSelection('\n' + indent + bullet + after, 'end');
|
||||
};
|
||||
|
||||
}());
|
87
plugins/codemirror/codemirror/addon/edit/matchbrackets.js
vendored
Normal file
87
plugins/codemirror/codemirror/addon/edit/matchbrackets.js
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
(function() {
|
||||
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
|
||||
(document.documentMode == null || document.documentMode < 8);
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
|
||||
function findMatchingBracket(cm, where, strict) {
|
||||
var state = cm.state.matchBrackets;
|
||||
var maxScanLen = (state && state.maxScanLineLength) || 10000;
|
||||
var maxScanLines = (state && state.maxScanLines) || 100;
|
||||
|
||||
var cur = where || cm.getCursor(), line = cm.getLineHandle(cur.line), pos = cur.ch - 1;
|
||||
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
|
||||
if (!match) return null;
|
||||
var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
|
||||
if (strict && forward != (pos == cur.ch)) return null;
|
||||
var style = cm.getTokenTypeAt(Pos(cur.line, pos + 1));
|
||||
|
||||
var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
|
||||
function scan(line, lineNo, start) {
|
||||
if (!line.text) return;
|
||||
var pos = forward ? 0 : line.text.length - 1, end = forward ? line.text.length : -1;
|
||||
if (line.text.length > maxScanLen) return null;
|
||||
if (start != null) pos = start + d;
|
||||
for (; pos != end; pos += d) {
|
||||
var ch = line.text.charAt(pos);
|
||||
if (re.test(ch) && cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style) {
|
||||
var match = matching[ch];
|
||||
if (match.charAt(1) == ">" == forward) stack.push(ch);
|
||||
else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
|
||||
else if (!stack.length) return {pos: pos, match: true};
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var i = cur.line, found, e = forward ? Math.min(i + maxScanLines, cm.lineCount()) : Math.max(-1, i - maxScanLines); i != e; i+=d) {
|
||||
if (i == cur.line) found = scan(line, i, pos);
|
||||
else found = scan(cm.getLineHandle(i), i);
|
||||
if (found) break;
|
||||
}
|
||||
return {from: Pos(cur.line, pos), to: found && Pos(i, found.pos),
|
||||
match: found && found.match, forward: forward};
|
||||
}
|
||||
|
||||
function matchBrackets(cm, autoclear) {
|
||||
// Disable brace matching in long lines, since it'll cause hugely slow updates
|
||||
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
|
||||
var found = findMatchingBracket(cm);
|
||||
if (!found || cm.getLine(found.from.line).length > maxHighlightLen ||
|
||||
found.to && cm.getLine(found.to.line).length > maxHighlightLen)
|
||||
return;
|
||||
|
||||
var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
||||
var one = cm.markText(found.from, Pos(found.from.line, found.from.ch + 1), {className: style});
|
||||
var two = found.to && cm.markText(found.to, Pos(found.to.line, found.to.ch + 1), {className: style});
|
||||
// Kludge to work around the IE bug from issue #1193, where text
|
||||
// input stops going to the textare whever this fires.
|
||||
if (ie_lt8 && cm.state.focused) cm.display.input.focus();
|
||||
var clear = function() {
|
||||
cm.operation(function() { one.clear(); two && two.clear(); });
|
||||
};
|
||||
if (autoclear) setTimeout(clear, 800);
|
||||
else return clear;
|
||||
}
|
||||
|
||||
var currentlyHighlighted = null;
|
||||
function doMatchBrackets(cm) {
|
||||
cm.operation(function() {
|
||||
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
|
||||
if (!cm.somethingSelected()) currentlyHighlighted = matchBrackets(cm, false);
|
||||
});
|
||||
}
|
||||
|
||||
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init)
|
||||
cm.off("cursorActivity", doMatchBrackets);
|
||||
if (val) {
|
||||
cm.state.matchBrackets = typeof val == "object" ? val : {};
|
||||
cm.on("cursorActivity", doMatchBrackets);
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
|
||||
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict){
|
||||
return findMatchingBracket(this, pos, strict);
|
||||
});
|
||||
})();
|
56
plugins/codemirror/codemirror/addon/edit/matchtags.js
vendored
Normal file
56
plugins/codemirror/codemirror/addon/edit/matchtags.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init) {
|
||||
cm.off("cursorActivity", doMatchTags);
|
||||
cm.off("viewportChange", maybeUpdateMatch);
|
||||
clear(cm);
|
||||
}
|
||||
if (val) {
|
||||
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
|
||||
cm.on("cursorActivity", doMatchTags);
|
||||
cm.on("viewportChange", maybeUpdateMatch);
|
||||
doMatchTags(cm);
|
||||
}
|
||||
});
|
||||
|
||||
function clear(cm) {
|
||||
if (cm.state.tagHit) cm.state.tagHit.clear();
|
||||
if (cm.state.tagOther) cm.state.tagOther.clear();
|
||||
cm.state.tagHit = cm.state.tagOther = null;
|
||||
}
|
||||
|
||||
function doMatchTags(cm) {
|
||||
cm.state.failedTagMatch = false;
|
||||
cm.operation(function() {
|
||||
clear(cm);
|
||||
if (cm.somethingSelected()) return;
|
||||
var cur = cm.getCursor(), range = cm.getViewport();
|
||||
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
|
||||
var match = CodeMirror.findMatchingTag(cm, cur, range);
|
||||
if (!match) return;
|
||||
if (cm.state.matchBothTags) {
|
||||
var hit = match.at == "open" ? match.open : match.close;
|
||||
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
|
||||
}
|
||||
var other = match.at == "close" ? match.open : match.close;
|
||||
if (other)
|
||||
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
|
||||
else
|
||||
cm.state.failedTagMatch = true;
|
||||
});
|
||||
}
|
||||
|
||||
function maybeUpdateMatch(cm) {
|
||||
if (cm.state.failedTagMatch) doMatchTags(cm);
|
||||
}
|
||||
|
||||
CodeMirror.commands.toMatchingTag = function(cm) {
|
||||
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
|
||||
if (found) {
|
||||
var other = found.at == "close" ? found.open : found.close;
|
||||
if (other) cm.setSelection(other.to, other.from);
|
||||
}
|
||||
};
|
||||
})();
|
15
plugins/codemirror/codemirror/addon/edit/trailingspace.js
vendored
Normal file
15
plugins/codemirror/codemirror/addon/edit/trailingspace.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
|
||||
if (prev == CodeMirror.Init) prev = false;
|
||||
if (prev && !val)
|
||||
cm.removeOverlay("trailingspace");
|
||||
else if (!prev && val)
|
||||
cm.addOverlay({
|
||||
token: function(stream) {
|
||||
for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
|
||||
if (i > stream.pos) { stream.pos = i; return null; }
|
||||
stream.pos = l;
|
||||
return "trailingspace";
|
||||
},
|
||||
name: "trailingspace"
|
||||
});
|
||||
});
|
93
plugins/codemirror/codemirror/addon/fold/brace-fold.js
vendored
Normal file
93
plugins/codemirror/codemirror/addon/fold/brace-fold.js
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
|
||||
var line = start.line, lineText = cm.getLine(line);
|
||||
var startCh, tokenType;
|
||||
|
||||
function findOpening(openCh) {
|
||||
for (var at = start.ch, pass = 0;;) {
|
||||
var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
|
||||
if (found == -1) {
|
||||
if (pass == 1) break;
|
||||
pass = 1;
|
||||
at = lineText.length;
|
||||
continue;
|
||||
}
|
||||
if (pass == 1 && found < start.ch) break;
|
||||
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
|
||||
if (!/^(comment|string)/.test(tokenType)) return found + 1;
|
||||
at = found - 1;
|
||||
}
|
||||
}
|
||||
|
||||
var startToken = "{", endToken = "}", startCh = findOpening("{");
|
||||
if (startCh == null) {
|
||||
startToken = "[", endToken = "]";
|
||||
startCh = findOpening("[");
|
||||
}
|
||||
|
||||
if (startCh == null) return;
|
||||
var count = 1, lastLine = cm.lastLine(), end, endCh;
|
||||
outer: for (var i = line; i <= lastLine; ++i) {
|
||||
var text = cm.getLine(i), pos = i == line ? startCh : 0;
|
||||
for (;;) {
|
||||
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
|
||||
if (nextOpen < 0) nextOpen = text.length;
|
||||
if (nextClose < 0) nextClose = text.length;
|
||||
pos = Math.min(nextOpen, nextClose);
|
||||
if (pos == text.length) break;
|
||||
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
|
||||
if (pos == nextOpen) ++count;
|
||||
else if (!--count) { end = i; endCh = pos; break outer; }
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
if (end == null || line == end && endCh == startCh) return;
|
||||
return {from: CodeMirror.Pos(line, startCh),
|
||||
to: CodeMirror.Pos(end, endCh)};
|
||||
});
|
||||
CodeMirror.braceRangeFinder = CodeMirror.fold.brace; // deprecated
|
||||
|
||||
CodeMirror.registerHelper("fold", "import", function(cm, start) {
|
||||
function hasImport(line) {
|
||||
if (line < cm.firstLine() || line > cm.lastLine()) return null;
|
||||
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
|
||||
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
|
||||
if (start.type != "keyword" || start.string != "import") return null;
|
||||
// Now find closing semicolon, return its position
|
||||
for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
|
||||
var text = cm.getLine(i), semi = text.indexOf(";");
|
||||
if (semi != -1) return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
|
||||
}
|
||||
}
|
||||
|
||||
var start = start.line, has = hasImport(start), prev;
|
||||
if (!has || hasImport(start - 1) || ((prev = hasImport(start - 2)) && prev.end.line == start - 1))
|
||||
return null;
|
||||
for (var end = has.end;;) {
|
||||
var next = hasImport(end.line + 1);
|
||||
if (next == null) break;
|
||||
end = next.end;
|
||||
}
|
||||
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
|
||||
});
|
||||
CodeMirror.importRangeFinder = CodeMirror.fold["import"]; // deprecated
|
||||
|
||||
CodeMirror.registerHelper("fold", "include", function(cm, start) {
|
||||
function hasInclude(line) {
|
||||
if (line < cm.firstLine() || line > cm.lastLine()) return null;
|
||||
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
|
||||
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
|
||||
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
|
||||
}
|
||||
|
||||
var start = start.line, has = hasInclude(start);
|
||||
if (has == null || hasInclude(start - 1) != null) return null;
|
||||
for (var end = start;;) {
|
||||
var next = hasInclude(end + 1);
|
||||
if (next == null) break;
|
||||
++end;
|
||||
}
|
||||
return {from: CodeMirror.Pos(start, has + 1),
|
||||
to: cm.clipPos(CodeMirror.Pos(end))};
|
||||
});
|
||||
CodeMirror.includeRangeFinder = CodeMirror.fold.include; // deprecated
|
40
plugins/codemirror/codemirror/addon/fold/comment-fold.js
vendored
Normal file
40
plugins/codemirror/codemirror/addon/fold/comment-fold.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
CodeMirror.registerHelper("fold", "comment", function(cm, start) {
|
||||
var mode = cm.getModeAt(start), startToken = mode.blockCommentStart, endToken = mode.blockCommentEnd;
|
||||
if (!startToken || !endToken) return;
|
||||
var line = start.line, lineText = cm.getLine(line);
|
||||
|
||||
var startCh;
|
||||
for (var at = start.ch, pass = 0;;) {
|
||||
var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);
|
||||
if (found == -1) {
|
||||
if (pass == 1) return;
|
||||
pass = 1;
|
||||
at = lineText.length;
|
||||
continue;
|
||||
}
|
||||
if (pass == 1 && found < start.ch) return;
|
||||
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1)))) {
|
||||
startCh = found + startToken.length;
|
||||
break;
|
||||
}
|
||||
at = found - 1;
|
||||
}
|
||||
|
||||
var depth = 1, lastLine = cm.lastLine(), end, endCh;
|
||||
outer: for (var i = line; i <= lastLine; ++i) {
|
||||
var text = cm.getLine(i), pos = i == line ? startCh : 0;
|
||||
for (;;) {
|
||||
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
|
||||
if (nextOpen < 0) nextOpen = text.length;
|
||||
if (nextClose < 0) nextClose = text.length;
|
||||
pos = Math.min(nextOpen, nextClose);
|
||||
if (pos == text.length) break;
|
||||
if (pos == nextOpen) ++depth;
|
||||
else if (!--depth) { end = i; endCh = pos; break outer; }
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
if (end == null || line == end && endCh == startCh) return;
|
||||
return {from: CodeMirror.Pos(line, startCh),
|
||||
to: CodeMirror.Pos(end, endCh)};
|
||||
});
|
75
plugins/codemirror/codemirror/addon/fold/foldcode.js
vendored
Normal file
75
plugins/codemirror/codemirror/addon/fold/foldcode.js
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
function doFold(cm, pos, options, force) {
|
||||
var finder = options && (options.call ? options : options.rangeFinder);
|
||||
if (!finder) finder = cm.getHelper(pos, "fold");
|
||||
if (!finder) return;
|
||||
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
|
||||
var minSize = options && options.minFoldSize || 0;
|
||||
|
||||
function getRange(allowFolded) {
|
||||
var range = finder(cm, pos);
|
||||
if (!range || range.to.line - range.from.line < minSize) return null;
|
||||
var marks = cm.findMarksAt(range.from);
|
||||
for (var i = 0; i < marks.length; ++i) {
|
||||
if (marks[i].__isFold && force !== "fold") {
|
||||
if (!allowFolded) return null;
|
||||
range.cleared = true;
|
||||
marks[i].clear();
|
||||
}
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
var range = getRange(true);
|
||||
if (options && options.scanUp) while (!range && pos.line > cm.firstLine()) {
|
||||
pos = CodeMirror.Pos(pos.line - 1, 0);
|
||||
range = getRange(false);
|
||||
}
|
||||
if (!range || range.cleared || force === "unfold") return;
|
||||
|
||||
var myWidget = makeWidget(options);
|
||||
CodeMirror.on(myWidget, "mousedown", function() { myRange.clear(); });
|
||||
var myRange = cm.markText(range.from, range.to, {
|
||||
replacedWith: myWidget,
|
||||
clearOnEnter: true,
|
||||
__isFold: true
|
||||
});
|
||||
myRange.on("clear", function(from, to) {
|
||||
CodeMirror.signal(cm, "unfold", cm, from, to);
|
||||
});
|
||||
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
|
||||
}
|
||||
|
||||
function makeWidget(options) {
|
||||
var widget = (options && options.widget) || "\u2194";
|
||||
if (typeof widget == "string") {
|
||||
var text = document.createTextNode(widget);
|
||||
widget = document.createElement("span");
|
||||
widget.appendChild(text);
|
||||
widget.className = "CodeMirror-foldmarker";
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
// Clumsy backwards-compatible interface
|
||||
CodeMirror.newFoldFunction = function(rangeFinder, widget) {
|
||||
return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
|
||||
};
|
||||
|
||||
// New-style interface
|
||||
CodeMirror.defineExtension("foldCode", function(pos, options, force) {
|
||||
doFold(this, pos, options, force);
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("fold", "combine", function() {
|
||||
var funcs = Array.prototype.slice.call(arguments, 0);
|
||||
return function(cm, start) {
|
||||
for (var i = 0; i < funcs.length; ++i) {
|
||||
var found = funcs[i](cm, start);
|
||||
if (found) return found;
|
||||
}
|
||||
};
|
||||
});
|
||||
})();
|
21
plugins/codemirror/codemirror/addon/fold/foldgutter.css
vendored
Normal file
21
plugins/codemirror/codemirror/addon/fold/foldgutter.css
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
.CodeMirror-foldmarker {
|
||||
color: blue;
|
||||
text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px;
|
||||
font-family: arial;
|
||||
line-height: .3;
|
||||
cursor: pointer;
|
||||
}
|
||||
.CodeMirror-foldgutter {
|
||||
width: .7em;
|
||||
}
|
||||
.CodeMirror-foldgutter-open,
|
||||
.CodeMirror-foldgutter-folded {
|
||||
color: #555;
|
||||
cursor: pointer;
|
||||
}
|
||||
.CodeMirror-foldgutter-open:after {
|
||||
content: "\25BE";
|
||||
}
|
||||
.CodeMirror-foldgutter-folded:after {
|
||||
content: "\25B8";
|
||||
}
|
124
plugins/codemirror/codemirror/addon/fold/foldgutter.js
vendored
Normal file
124
plugins/codemirror/codemirror/addon/fold/foldgutter.js
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init) {
|
||||
cm.clearGutter(cm.state.foldGutter.options.gutter);
|
||||
cm.state.foldGutter = null;
|
||||
cm.off("gutterClick", onGutterClick);
|
||||
cm.off("change", onChange);
|
||||
cm.off("viewportChange", onViewportChange);
|
||||
cm.off("fold", onFold);
|
||||
cm.off("unfold", onFold);
|
||||
cm.off("swapDoc", updateInViewport);
|
||||
}
|
||||
if (val) {
|
||||
cm.state.foldGutter = new State(parseOptions(val));
|
||||
updateInViewport(cm);
|
||||
cm.on("gutterClick", onGutterClick);
|
||||
cm.on("change", onChange);
|
||||
cm.on("viewportChange", onViewportChange);
|
||||
cm.on("fold", onFold);
|
||||
cm.on("unfold", onFold);
|
||||
cm.on("swapDoc", updateInViewport);
|
||||
}
|
||||
});
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function State(options) {
|
||||
this.options = options;
|
||||
this.from = this.to = 0;
|
||||
}
|
||||
|
||||
function parseOptions(opts) {
|
||||
if (opts === true) opts = {};
|
||||
if (opts.gutter == null) opts.gutter = "CodeMirror-foldgutter";
|
||||
if (opts.indicatorOpen == null) opts.indicatorOpen = "CodeMirror-foldgutter-open";
|
||||
if (opts.indicatorFolded == null) opts.indicatorFolded = "CodeMirror-foldgutter-folded";
|
||||
return opts;
|
||||
}
|
||||
|
||||
function isFolded(cm, line) {
|
||||
var marks = cm.findMarksAt(Pos(line));
|
||||
for (var i = 0; i < marks.length; ++i)
|
||||
if (marks[i].__isFold && marks[i].find().from.line == line) return true;
|
||||
}
|
||||
|
||||
function marker(spec) {
|
||||
if (typeof spec == "string") {
|
||||
var elt = document.createElement("div");
|
||||
elt.className = spec;
|
||||
return elt;
|
||||
} else {
|
||||
return spec.cloneNode(true);
|
||||
}
|
||||
}
|
||||
|
||||
function updateFoldInfo(cm, from, to) {
|
||||
var opts = cm.state.foldGutter.options, cur = from;
|
||||
cm.eachLine(from, to, function(line) {
|
||||
var mark = null;
|
||||
if (isFolded(cm, cur)) {
|
||||
mark = marker(opts.indicatorFolded);
|
||||
} else {
|
||||
var pos = Pos(cur, 0), func = opts.rangeFinder || cm.getHelper(pos, "fold");
|
||||
var range = func && func(cm, pos);
|
||||
if (range && range.from.line + 1 < range.to.line)
|
||||
mark = marker(opts.indicatorOpen);
|
||||
}
|
||||
cm.setGutterMarker(line, opts.gutter, mark);
|
||||
++cur;
|
||||
});
|
||||
}
|
||||
|
||||
function updateInViewport(cm) {
|
||||
var vp = cm.getViewport(), state = cm.state.foldGutter;
|
||||
if (!state) return;
|
||||
cm.operation(function() {
|
||||
updateFoldInfo(cm, vp.from, vp.to);
|
||||
});
|
||||
state.from = vp.from; state.to = vp.to;
|
||||
}
|
||||
|
||||
function onGutterClick(cm, line, gutter) {
|
||||
var opts = cm.state.foldGutter.options;
|
||||
if (gutter != opts.gutter) return;
|
||||
cm.foldCode(Pos(line, 0), opts.rangeFinder);
|
||||
}
|
||||
|
||||
function onChange(cm) {
|
||||
var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
|
||||
state.from = state.to = 0;
|
||||
clearTimeout(state.changeUpdate);
|
||||
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
|
||||
}
|
||||
|
||||
function onViewportChange(cm) {
|
||||
var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
|
||||
clearTimeout(state.changeUpdate);
|
||||
state.changeUpdate = setTimeout(function() {
|
||||
var vp = cm.getViewport();
|
||||
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
|
||||
updateInViewport(cm);
|
||||
} else {
|
||||
cm.operation(function() {
|
||||
if (vp.from < state.from) {
|
||||
updateFoldInfo(cm, vp.from, state.from);
|
||||
state.from = vp.from;
|
||||
}
|
||||
if (vp.to > state.to) {
|
||||
updateFoldInfo(cm, state.to, vp.to);
|
||||
state.to = vp.to;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, opts.updateViewportTimeSpan || 400);
|
||||
}
|
||||
|
||||
function onFold(cm, from) {
|
||||
var state = cm.state.foldGutter, line = from.line;
|
||||
if (line >= state.from && line < state.to)
|
||||
updateFoldInfo(cm, line, line + 1);
|
||||
}
|
||||
})();
|
30
plugins/codemirror/codemirror/addon/fold/indent-fold.js
vendored
Normal file
30
plugins/codemirror/codemirror/addon/fold/indent-fold.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
|
||||
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
|
||||
if (!/\S/.test(firstLine)) return;
|
||||
var getIndent = function(lineNum) {
|
||||
return CodeMirror.countColumn(lineNum, null, tabSize);
|
||||
};
|
||||
var myIndent = getIndent(firstLine);
|
||||
var lastLineInFold = null;
|
||||
// Go through lines until we find a line that definitely doesn't belong in
|
||||
// the block we're folding, or to the end.
|
||||
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
|
||||
var curLine = cm.getLine(i);
|
||||
var curIndent = getIndent(curLine);
|
||||
if (curIndent > myIndent) {
|
||||
// Lines with a greater indent are considered part of the block.
|
||||
lastLineInFold = i;
|
||||
} else if (!/\S/.test(curLine)) {
|
||||
// Empty lines might be breaks within the block we're trying to fold.
|
||||
} else {
|
||||
// A non-empty line at an indent equal to or less than ours marks the
|
||||
// start of another block.
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastLineInFold) return {
|
||||
from: CodeMirror.Pos(start.line, firstLine.length),
|
||||
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
|
||||
};
|
||||
});
|
||||
CodeMirror.indentRangeFinder = CodeMirror.fold.indent; // deprecated
|
167
plugins/codemirror/codemirror/addon/fold/xml-fold.js
vendored
Normal file
167
plugins/codemirror/codemirror/addon/fold/xml-fold.js
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
function cmp(a, b) { return a.line - b.line || a.ch - b.ch; }
|
||||
|
||||
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
||||
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
||||
var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g");
|
||||
|
||||
function Iter(cm, line, ch, range) {
|
||||
this.line = line; this.ch = ch;
|
||||
this.cm = cm; this.text = cm.getLine(line);
|
||||
this.min = range ? range.from : cm.firstLine();
|
||||
this.max = range ? range.to - 1 : cm.lastLine();
|
||||
}
|
||||
|
||||
function tagAt(iter, ch) {
|
||||
var type = iter.cm.getTokenTypeAt(Pos(iter.line, ch));
|
||||
return type && /\btag\b/.test(type);
|
||||
}
|
||||
|
||||
function nextLine(iter) {
|
||||
if (iter.line >= iter.max) return;
|
||||
iter.ch = 0;
|
||||
iter.text = iter.cm.getLine(++iter.line);
|
||||
return true;
|
||||
}
|
||||
function prevLine(iter) {
|
||||
if (iter.line <= iter.min) return;
|
||||
iter.text = iter.cm.getLine(--iter.line);
|
||||
iter.ch = iter.text.length;
|
||||
return true;
|
||||
}
|
||||
|
||||
function toTagEnd(iter) {
|
||||
for (;;) {
|
||||
var gt = iter.text.indexOf(">", iter.ch);
|
||||
if (gt == -1) { if (nextLine(iter)) continue; else return; }
|
||||
if (!tagAt(iter, gt + 1)) { iter.ch = gt + 1; continue; }
|
||||
var lastSlash = iter.text.lastIndexOf("/", gt);
|
||||
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
|
||||
iter.ch = gt + 1;
|
||||
return selfClose ? "selfClose" : "regular";
|
||||
}
|
||||
}
|
||||
function toTagStart(iter) {
|
||||
for (;;) {
|
||||
var lt = iter.ch ? iter.text.lastIndexOf("<", iter.ch - 1) : -1;
|
||||
if (lt == -1) { if (prevLine(iter)) continue; else return; }
|
||||
if (!tagAt(iter, lt + 1)) { iter.ch = lt; continue; }
|
||||
xmlTagStart.lastIndex = lt;
|
||||
iter.ch = lt;
|
||||
var match = xmlTagStart.exec(iter.text);
|
||||
if (match && match.index == lt) return match;
|
||||
}
|
||||
}
|
||||
|
||||
function toNextTag(iter) {
|
||||
for (;;) {
|
||||
xmlTagStart.lastIndex = iter.ch;
|
||||
var found = xmlTagStart.exec(iter.text);
|
||||
if (!found) { if (nextLine(iter)) continue; else return; }
|
||||
if (!tagAt(iter, found.index + 1)) { iter.ch = found.index + 1; continue; }
|
||||
iter.ch = found.index + found[0].length;
|
||||
return found;
|
||||
}
|
||||
}
|
||||
function toPrevTag(iter) {
|
||||
for (;;) {
|
||||
var gt = iter.ch ? iter.text.lastIndexOf(">", iter.ch - 1) : -1;
|
||||
if (gt == -1) { if (prevLine(iter)) continue; else return; }
|
||||
if (!tagAt(iter, gt + 1)) { iter.ch = gt; continue; }
|
||||
var lastSlash = iter.text.lastIndexOf("/", gt);
|
||||
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
|
||||
iter.ch = gt + 1;
|
||||
return selfClose ? "selfClose" : "regular";
|
||||
}
|
||||
}
|
||||
|
||||
function findMatchingClose(iter, tag) {
|
||||
var stack = [];
|
||||
for (;;) {
|
||||
var next = toNextTag(iter), end, startLine = iter.line, startCh = iter.ch - (next ? next[0].length : 0);
|
||||
if (!next || !(end = toTagEnd(iter))) return;
|
||||
if (end == "selfClose") continue;
|
||||
if (next[1]) { // closing tag
|
||||
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) {
|
||||
stack.length = i;
|
||||
break;
|
||||
}
|
||||
if (i < 0 && (!tag || tag == next[2])) return {
|
||||
tag: next[2],
|
||||
from: Pos(startLine, startCh),
|
||||
to: Pos(iter.line, iter.ch)
|
||||
};
|
||||
} else { // opening tag
|
||||
stack.push(next[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
function findMatchingOpen(iter, tag) {
|
||||
var stack = [];
|
||||
for (;;) {
|
||||
var prev = toPrevTag(iter);
|
||||
if (!prev) return;
|
||||
if (prev == "selfClose") { toTagStart(iter); continue; }
|
||||
var endLine = iter.line, endCh = iter.ch;
|
||||
var start = toTagStart(iter);
|
||||
if (!start) return;
|
||||
if (start[1]) { // closing tag
|
||||
stack.push(start[2]);
|
||||
} else { // opening tag
|
||||
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == start[2]) {
|
||||
stack.length = i;
|
||||
break;
|
||||
}
|
||||
if (i < 0 && (!tag || tag == start[2])) return {
|
||||
tag: start[2],
|
||||
from: Pos(iter.line, iter.ch),
|
||||
to: Pos(endLine, endCh)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("fold", "xml", function(cm, start) {
|
||||
var iter = new Iter(cm, start.line, 0);
|
||||
for (;;) {
|
||||
var openTag = toNextTag(iter), end;
|
||||
if (!openTag || iter.line != start.line || !(end = toTagEnd(iter))) return;
|
||||
if (!openTag[1] && end != "selfClose") {
|
||||
var start = Pos(iter.line, iter.ch);
|
||||
var close = findMatchingClose(iter, openTag[2]);
|
||||
return close && {from: start, to: close.from};
|
||||
}
|
||||
}
|
||||
});
|
||||
CodeMirror.tagRangeFinder = CodeMirror.fold.xml; // deprecated
|
||||
|
||||
CodeMirror.findMatchingTag = function(cm, pos, range) {
|
||||
var iter = new Iter(cm, pos.line, pos.ch, range);
|
||||
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
|
||||
var end = toTagEnd(iter), to = end && Pos(iter.line, iter.ch);
|
||||
var start = end && toTagStart(iter);
|
||||
if (!end || end == "selfClose" || !start || cmp(iter, pos) > 0) return;
|
||||
var here = {from: Pos(iter.line, iter.ch), to: to, tag: start[2]};
|
||||
|
||||
if (start[1]) { // closing tag
|
||||
return {open: findMatchingOpen(iter, start[2]), close: here, at: "close"};
|
||||
} else { // opening tag
|
||||
iter = new Iter(cm, to.line, to.ch, range);
|
||||
return {open: here, close: findMatchingClose(iter, start[2]), at: "open"};
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.findEnclosingTag = function(cm, pos, range) {
|
||||
var iter = new Iter(cm, pos.line, pos.ch, range);
|
||||
for (;;) {
|
||||
var open = findMatchingOpen(iter);
|
||||
if (!open) break;
|
||||
var forward = new Iter(cm, pos.line, pos.ch, range);
|
||||
var close = findMatchingClose(forward, open.tag);
|
||||
if (close) return {open: open, close: close};
|
||||
}
|
||||
};
|
||||
})();
|
34
plugins/codemirror/codemirror/addon/hint/anyword-hint.js
vendored
Normal file
34
plugins/codemirror/codemirror/addon/hint/anyword-hint.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var WORD = /[\w$]+/, RANGE = 500;
|
||||
|
||||
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
|
||||
var word = options && options.word || WORD;
|
||||
var range = options && options.range || RANGE;
|
||||
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
|
||||
var start = cur.ch, end = start;
|
||||
while (end < curLine.length && word.test(curLine.charAt(end))) ++end;
|
||||
while (start && word.test(curLine.charAt(start - 1))) --start;
|
||||
var curWord = start != end && curLine.slice(start, end);
|
||||
|
||||
var list = [], seen = {};
|
||||
function scan(dir) {
|
||||
var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
|
||||
for (; line != end; line += dir) {
|
||||
var text = editor.getLine(line), m;
|
||||
var re = new RegExp(word.source, "g");
|
||||
while (m = re.exec(text)) {
|
||||
if (line == cur.line && m[0] === curWord) continue;
|
||||
if ((!curWord || m[0].indexOf(curWord) == 0) && !seen.hasOwnProperty(m[0])) {
|
||||
seen[m[0]] = true;
|
||||
list.push(m[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scan(-1);
|
||||
scan(1);
|
||||
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
|
||||
});
|
||||
})();
|
50
plugins/codemirror/codemirror/addon/hint/css-hint.js
vendored
Normal file
50
plugins/codemirror/codemirror/addon/hint/css-hint.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function getHints(cm) {
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
|
||||
if (inner.mode.name != "css") return;
|
||||
|
||||
// If it's not a 'word-style' token, ignore the token.
|
||||
if (!/^[\w$_-]*$/.test(token.string)) {
|
||||
token = {
|
||||
start: cur.ch, end: cur.ch, string: "", state: token.state,
|
||||
type: null
|
||||
};
|
||||
var stack = token.state.stack;
|
||||
var lastToken = stack && stack.length > 0 ? stack[stack.length - 1] : "";
|
||||
if (token.string == ":" || lastToken.indexOf("property") == 0)
|
||||
token.type = "variable";
|
||||
else if (token.string == "{" || lastToken.indexOf("rule") == 0)
|
||||
token.type = "property";
|
||||
}
|
||||
|
||||
if (!token.type)
|
||||
return;
|
||||
|
||||
var spec = CodeMirror.resolveMode("text/css");
|
||||
var keywords = null;
|
||||
if (token.type.indexOf("property") == 0)
|
||||
keywords = spec.propertyKeywords;
|
||||
else if (token.type.indexOf("variable") == 0)
|
||||
keywords = spec.valueKeywords;
|
||||
|
||||
if (!keywords)
|
||||
return;
|
||||
|
||||
var result = [];
|
||||
for (var name in keywords) {
|
||||
if (name.indexOf(token.string) == 0 /* > -1 */)
|
||||
result.push(name);
|
||||
}
|
||||
|
||||
return {
|
||||
list: result,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)
|
||||
};
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("hint", "css", getHints);
|
||||
})();
|
337
plugins/codemirror/codemirror/addon/hint/html-hint.js
vendored
Normal file
337
plugins/codemirror/codemirror/addon/hint/html-hint.js
vendored
Normal file
@@ -0,0 +1,337 @@
|
||||
(function () {
|
||||
var langs = "ab aa af ak sq am ar an hy as av ae ay az bm ba eu be bn bh bi bs br bg my ca ch ce ny zh cv kw co cr hr cs da dv nl dz en eo et ee fo fj fi fr ff gl ka de el gn gu ht ha he hz hi ho hu ia id ie ga ig ik io is it iu ja jv kl kn kr ks kk km ki rw ky kv kg ko ku kj la lb lg li ln lo lt lu lv gv mk mg ms ml mt mi mr mh mn na nv nb nd ne ng nn no ii nr oc oj cu om or os pa pi fa pl ps pt qu rm rn ro ru sa sc sd se sm sg sr gd sn si sk sl so st es su sw ss sv ta te tg th ti bo tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa cy wo fy xh yi yo za zu".split(" ");
|
||||
var targets = ["_blank", "_self", "_top", "_parent"];
|
||||
var charsets = ["ascii", "utf-8", "utf-16", "latin1", "latin1"];
|
||||
var methods = ["get", "post", "put", "delete"];
|
||||
var encs = ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"];
|
||||
var media = ["all", "screen", "print", "embossed", "braille", "handheld", "print", "projection", "screen", "tty", "tv", "speech",
|
||||
"3d-glasses", "resolution [>][<][=] [X]", "device-aspect-ratio: X/Y", "orientation:portrait",
|
||||
"orientation:landscape", "device-height: [X]", "device-width: [X]"];
|
||||
var s = { attrs: {} }; // Simple tag, reused for a whole lot of tags
|
||||
|
||||
var data = {
|
||||
a: {
|
||||
attrs: {
|
||||
href: null, ping: null, type: null,
|
||||
media: media,
|
||||
target: targets,
|
||||
hreflang: langs
|
||||
}
|
||||
},
|
||||
abbr: s,
|
||||
acronym: s,
|
||||
address: s,
|
||||
applet: s,
|
||||
area: {
|
||||
attrs: {
|
||||
alt: null, coords: null, href: null, target: null, ping: null,
|
||||
media: media, hreflang: langs, type: null,
|
||||
shape: ["default", "rect", "circle", "poly"]
|
||||
}
|
||||
},
|
||||
article: s,
|
||||
aside: s,
|
||||
audio: {
|
||||
attrs: {
|
||||
src: null, mediagroup: null,
|
||||
crossorigin: ["anonymous", "use-credentials"],
|
||||
preload: ["none", "metadata", "auto"],
|
||||
autoplay: ["", "autoplay"],
|
||||
loop: ["", "loop"],
|
||||
controls: ["", "controls"]
|
||||
}
|
||||
},
|
||||
b: s,
|
||||
base: { attrs: { href: null, target: targets } },
|
||||
basefont: s,
|
||||
bdi: s,
|
||||
bdo: s,
|
||||
big: s,
|
||||
blockquote: { attrs: { cite: null } },
|
||||
body: s,
|
||||
br: s,
|
||||
button: {
|
||||
attrs: {
|
||||
form: null, formaction: null, name: null, value: null,
|
||||
autofocus: ["", "autofocus"],
|
||||
disabled: ["", "autofocus"],
|
||||
formenctype: encs,
|
||||
formmethod: methods,
|
||||
formnovalidate: ["", "novalidate"],
|
||||
formtarget: targets,
|
||||
type: ["submit", "reset", "button"]
|
||||
}
|
||||
},
|
||||
canvas: { attrs: { width: null, height: null } },
|
||||
caption: s,
|
||||
center: s,
|
||||
cite: s,
|
||||
code: s,
|
||||
col: { attrs: { span: null } },
|
||||
colgroup: { attrs: { span: null } },
|
||||
command: {
|
||||
attrs: {
|
||||
type: ["command", "checkbox", "radio"],
|
||||
label: null, icon: null, radiogroup: null, command: null, title: null,
|
||||
disabled: ["", "disabled"],
|
||||
checked: ["", "checked"]
|
||||
}
|
||||
},
|
||||
data: { attrs: { value: null } },
|
||||
datagrid: { attrs: { disabled: ["", "disabled"], multiple: ["", "multiple"] } },
|
||||
datalist: { attrs: { data: null } },
|
||||
dd: s,
|
||||
del: { attrs: { cite: null, datetime: null } },
|
||||
details: { attrs: { open: ["", "open"] } },
|
||||
dfn: s,
|
||||
dir: s,
|
||||
div: s,
|
||||
dl: s,
|
||||
dt: s,
|
||||
em: s,
|
||||
embed: { attrs: { src: null, type: null, width: null, height: null } },
|
||||
eventsource: { attrs: { src: null } },
|
||||
fieldset: { attrs: { disabled: ["", "disabled"], form: null, name: null } },
|
||||
figcaption: s,
|
||||
figure: s,
|
||||
font: s,
|
||||
footer: s,
|
||||
form: {
|
||||
attrs: {
|
||||
action: null, name: null,
|
||||
"accept-charset": charsets,
|
||||
autocomplete: ["on", "off"],
|
||||
enctype: encs,
|
||||
method: methods,
|
||||
novalidate: ["", "novalidate"],
|
||||
target: targets
|
||||
}
|
||||
},
|
||||
frame: s,
|
||||
frameset: s,
|
||||
h1: s, h2: s, h3: s, h4: s, h5: s, h6: s,
|
||||
head: {
|
||||
attrs: {},
|
||||
children: ["title", "base", "link", "style", "meta", "script", "noscript", "command"]
|
||||
},
|
||||
header: s,
|
||||
hgroup: s,
|
||||
hr: s,
|
||||
html: {
|
||||
attrs: { manifest: null },
|
||||
children: ["head", "body"]
|
||||
},
|
||||
i: s,
|
||||
iframe: {
|
||||
attrs: {
|
||||
src: null, srcdoc: null, name: null, width: null, height: null,
|
||||
sandbox: ["allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts"],
|
||||
seamless: ["", "seamless"]
|
||||
}
|
||||
},
|
||||
img: {
|
||||
attrs: {
|
||||
alt: null, src: null, ismap: null, usemap: null, width: null, height: null,
|
||||
crossorigin: ["anonymous", "use-credentials"]
|
||||
}
|
||||
},
|
||||
input: {
|
||||
attrs: {
|
||||
alt: null, dirname: null, form: null, formaction: null,
|
||||
height: null, list: null, max: null, maxlength: null, min: null,
|
||||
name: null, pattern: null, placeholder: null, size: null, src: null,
|
||||
step: null, value: null, width: null,
|
||||
accept: ["audio/*", "video/*", "image/*"],
|
||||
autocomplete: ["on", "off"],
|
||||
autofocus: ["", "autofocus"],
|
||||
checked: ["", "checked"],
|
||||
disabled: ["", "disabled"],
|
||||
formenctype: encs,
|
||||
formmethod: methods,
|
||||
formnovalidate: ["", "novalidate"],
|
||||
formtarget: targets,
|
||||
multiple: ["", "multiple"],
|
||||
readonly: ["", "readonly"],
|
||||
required: ["", "required"],
|
||||
type: ["hidden", "text", "search", "tel", "url", "email", "password", "datetime", "date", "month",
|
||||
"week", "time", "datetime-local", "number", "range", "color", "checkbox", "radio",
|
||||
"file", "submit", "image", "reset", "button"]
|
||||
}
|
||||
},
|
||||
ins: { attrs: { cite: null, datetime: null } },
|
||||
kbd: s,
|
||||
keygen: {
|
||||
attrs: {
|
||||
challenge: null, form: null, name: null,
|
||||
autofocus: ["", "autofocus"],
|
||||
disabled: ["", "disabled"],
|
||||
keytype: ["RSA"]
|
||||
}
|
||||
},
|
||||
label: { attrs: { "for": null, form: null } },
|
||||
legend: s,
|
||||
li: { attrs: { value: null } },
|
||||
link: {
|
||||
attrs: {
|
||||
href: null, type: null,
|
||||
hreflang: langs,
|
||||
media: media,
|
||||
sizes: ["all", "16x16", "16x16 32x32", "16x16 32x32 64x64"]
|
||||
}
|
||||
},
|
||||
map: { attrs: { name: null } },
|
||||
mark: s,
|
||||
menu: { attrs: { label: null, type: ["list", "context", "toolbar"] } },
|
||||
meta: {
|
||||
attrs: {
|
||||
content: null,
|
||||
charset: charsets,
|
||||
name: ["viewport", "application-name", "author", "description", "generator", "keywords"],
|
||||
"http-equiv": ["content-language", "content-type", "default-style", "refresh"]
|
||||
}
|
||||
},
|
||||
meter: { attrs: { value: null, min: null, low: null, high: null, max: null, optimum: null } },
|
||||
nav: s,
|
||||
noframes: s,
|
||||
noscript: s,
|
||||
object: {
|
||||
attrs: {
|
||||
data: null, type: null, name: null, usemap: null, form: null, width: null, height: null,
|
||||
typemustmatch: ["", "typemustmatch"]
|
||||
}
|
||||
},
|
||||
ol: { attrs: { reversed: ["", "reversed"], start: null, type: ["1", "a", "A", "i", "I"] } },
|
||||
optgroup: { attrs: { disabled: ["", "disabled"], label: null } },
|
||||
option: { attrs: { disabled: ["", "disabled"], label: null, selected: ["", "selected"], value: null } },
|
||||
output: { attrs: { "for": null, form: null, name: null } },
|
||||
p: s,
|
||||
param: { attrs: { name: null, value: null } },
|
||||
pre: s,
|
||||
progress: { attrs: { value: null, max: null } },
|
||||
q: { attrs: { cite: null } },
|
||||
rp: s,
|
||||
rt: s,
|
||||
ruby: s,
|
||||
s: s,
|
||||
samp: s,
|
||||
script: {
|
||||
attrs: {
|
||||
type: ["text/javascript"],
|
||||
src: null,
|
||||
async: ["", "async"],
|
||||
defer: ["", "defer"],
|
||||
charset: charsets
|
||||
}
|
||||
},
|
||||
section: s,
|
||||
select: {
|
||||
attrs: {
|
||||
form: null, name: null, size: null,
|
||||
autofocus: ["", "autofocus"],
|
||||
disabled: ["", "disabled"],
|
||||
multiple: ["", "multiple"]
|
||||
}
|
||||
},
|
||||
small: s,
|
||||
source: { attrs: { src: null, type: null, media: null } },
|
||||
span: s,
|
||||
strike: s,
|
||||
strong: s,
|
||||
style: {
|
||||
attrs: {
|
||||
type: ["text/css"],
|
||||
media: media,
|
||||
scoped: null
|
||||
}
|
||||
},
|
||||
sub: s,
|
||||
summary: s,
|
||||
sup: s,
|
||||
table: s,
|
||||
tbody: s,
|
||||
td: { attrs: { colspan: null, rowspan: null, headers: null } },
|
||||
textarea: {
|
||||
attrs: {
|
||||
dirname: null, form: null, maxlength: null, name: null, placeholder: null,
|
||||
rows: null, cols: null,
|
||||
autofocus: ["", "autofocus"],
|
||||
disabled: ["", "disabled"],
|
||||
readonly: ["", "readonly"],
|
||||
required: ["", "required"],
|
||||
wrap: ["soft", "hard"]
|
||||
}
|
||||
},
|
||||
tfoot: s,
|
||||
th: { attrs: { colspan: null, rowspan: null, headers: null, scope: ["row", "col", "rowgroup", "colgroup"] } },
|
||||
thead: s,
|
||||
time: { attrs: { datetime: null } },
|
||||
title: s,
|
||||
tr: s,
|
||||
track: {
|
||||
attrs: {
|
||||
src: null, label: null, "default": null,
|
||||
kind: ["subtitles", "captions", "descriptions", "chapters", "metadata"],
|
||||
srclang: langs
|
||||
}
|
||||
},
|
||||
tt: s,
|
||||
u: s,
|
||||
ul: s,
|
||||
"var": s,
|
||||
video: {
|
||||
attrs: {
|
||||
src: null, poster: null, width: null, height: null,
|
||||
crossorigin: ["anonymous", "use-credentials"],
|
||||
preload: ["auto", "metadata", "none"],
|
||||
autoplay: ["", "autoplay"],
|
||||
mediagroup: ["movie"],
|
||||
muted: ["", "muted"],
|
||||
controls: ["", "controls"]
|
||||
}
|
||||
},
|
||||
wbr: s
|
||||
};
|
||||
|
||||
var globalAttrs = {
|
||||
accesskey: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
|
||||
"class": null,
|
||||
contenteditable: ["true", "false"],
|
||||
contextmenu: null,
|
||||
dir: ["ltr", "rtl", "auto"],
|
||||
draggable: ["true", "false", "auto"],
|
||||
dropzone: ["copy", "move", "link", "string:", "file:"],
|
||||
hidden: ["hidden"],
|
||||
id: null,
|
||||
inert: ["inert"],
|
||||
itemid: null,
|
||||
itemprop: null,
|
||||
itemref: null,
|
||||
itemscope: ["itemscope"],
|
||||
itemtype: null,
|
||||
lang: ["en", "es"],
|
||||
spellcheck: ["true", "false"],
|
||||
style: null,
|
||||
tabindex: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
|
||||
title: null,
|
||||
translate: ["yes", "no"],
|
||||
onclick: null,
|
||||
rel: ["stylesheet", "alternate", "author", "bookmark", "help", "license", "next", "nofollow", "noreferrer", "prefetch", "prev", "search", "tag"]
|
||||
};
|
||||
function populate(obj) {
|
||||
for (var attr in globalAttrs) if (globalAttrs.hasOwnProperty(attr))
|
||||
obj.attrs[attr] = globalAttrs[attr];
|
||||
}
|
||||
|
||||
populate(s);
|
||||
for (var tag in data) if (data.hasOwnProperty(tag) && data[tag] != s)
|
||||
populate(data[tag]);
|
||||
|
||||
CodeMirror.htmlSchema = data;
|
||||
function htmlHint(cm, options) {
|
||||
var local = {schemaInfo: data};
|
||||
if (options) for (var opt in options) local[opt] = options[opt];
|
||||
return CodeMirror.hint.xml(cm, local);
|
||||
}
|
||||
CodeMirror.htmlHint = htmlHint; // deprecated
|
||||
CodeMirror.registerHelper("hint", "html", htmlHint);
|
||||
})();
|
131
plugins/codemirror/codemirror/addon/hint/javascript-hint.js
vendored
Normal file
131
plugins/codemirror/codemirror/addon/hint/javascript-hint.js
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
(function () {
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function forEach(arr, f) {
|
||||
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
||||
}
|
||||
|
||||
function arrayContains(arr, item) {
|
||||
if (!Array.prototype.indexOf) {
|
||||
var i = arr.length;
|
||||
while (i--) {
|
||||
if (arr[i] === item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return arr.indexOf(item) != -1;
|
||||
}
|
||||
|
||||
function scriptHint(editor, keywords, getToken, options) {
|
||||
// Find the token at the cursor
|
||||
var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
|
||||
if (/\b(?:string|comment)\b/.test(token.type)) return;
|
||||
token.state = CodeMirror.innerMode(editor.getMode(), token.state).state;
|
||||
|
||||
// If it's not a 'word-style' token, ignore the token.
|
||||
if (!/^[\w$_]*$/.test(token.string)) {
|
||||
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
||||
type: token.string == "." ? "property" : null};
|
||||
}
|
||||
// If it is a property, find out what it is a property of.
|
||||
while (tprop.type == "property") {
|
||||
tprop = getToken(editor, Pos(cur.line, tprop.start));
|
||||
if (tprop.string != ".") return;
|
||||
tprop = getToken(editor, Pos(cur.line, tprop.start));
|
||||
if (!context) var context = [];
|
||||
context.push(tprop);
|
||||
}
|
||||
return {list: getCompletions(token, context, keywords, options),
|
||||
from: Pos(cur.line, token.start),
|
||||
to: Pos(cur.line, token.end)};
|
||||
}
|
||||
|
||||
function javascriptHint(editor, options) {
|
||||
return scriptHint(editor, javascriptKeywords,
|
||||
function (e, cur) {return e.getTokenAt(cur);},
|
||||
options);
|
||||
};
|
||||
CodeMirror.javascriptHint = javascriptHint; // deprecated
|
||||
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
|
||||
|
||||
function getCoffeeScriptToken(editor, cur) {
|
||||
// This getToken, it is for coffeescript, imitates the behavior of
|
||||
// getTokenAt method in javascript.js, that is, returning "property"
|
||||
// type and treat "." as indepenent token.
|
||||
var token = editor.getTokenAt(cur);
|
||||
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
|
||||
token.end = token.start;
|
||||
token.string = '.';
|
||||
token.type = "property";
|
||||
}
|
||||
else if (/^\.[\w$_]*$/.test(token.string)) {
|
||||
token.type = "property";
|
||||
token.start++;
|
||||
token.string = token.string.replace(/\./, '');
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
function coffeescriptHint(editor, options) {
|
||||
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
|
||||
}
|
||||
CodeMirror.coffeescriptHint = coffeescriptHint; // deprecated
|
||||
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
|
||||
|
||||
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
|
||||
"toUpperCase toLowerCase split concat match replace search").split(" ");
|
||||
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
|
||||
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
|
||||
var funcProps = "prototype apply call bind".split(" ");
|
||||
var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
|
||||
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
|
||||
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
|
||||
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
|
||||
|
||||
function getCompletions(token, context, keywords, options) {
|
||||
var found = [], start = token.string;
|
||||
function maybeAdd(str) {
|
||||
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
|
||||
}
|
||||
function gatherCompletions(obj) {
|
||||
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
||||
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
||||
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
||||
for (var name in obj) maybeAdd(name);
|
||||
}
|
||||
|
||||
if (context && context.length) {
|
||||
// If this is a property, see if it belongs to some object we can
|
||||
// find in the current environment.
|
||||
var obj = context.pop(), base;
|
||||
if (obj.type && obj.type.indexOf("variable") === 0) {
|
||||
if (options && options.additionalContext)
|
||||
base = options.additionalContext[obj.string];
|
||||
base = base || window[obj.string];
|
||||
} else if (obj.type == "string") {
|
||||
base = "";
|
||||
} else if (obj.type == "atom") {
|
||||
base = 1;
|
||||
} else if (obj.type == "function") {
|
||||
if (window.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
|
||||
(typeof window.jQuery == 'function'))
|
||||
base = window.jQuery();
|
||||
else if (window._ != null && (obj.string == '_') && (typeof window._ == 'function'))
|
||||
base = window._();
|
||||
}
|
||||
while (base != null && context.length)
|
||||
base = base[context.pop().string];
|
||||
if (base != null) gatherCompletions(base);
|
||||
} else {
|
||||
// If not, just look in the window object and any local scope
|
||||
// (reading into JS mode internals to get at the local and global variables)
|
||||
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
||||
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
|
||||
gatherCompletions(window);
|
||||
forEach(keywords, maybeAdd);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
})();
|
121
plugins/codemirror/codemirror/addon/hint/pig-hint.js
vendored
Normal file
121
plugins/codemirror/codemirror/addon/hint/pig-hint.js
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function forEach(arr, f) {
|
||||
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
||||
}
|
||||
|
||||
function arrayContains(arr, item) {
|
||||
if (!Array.prototype.indexOf) {
|
||||
var i = arr.length;
|
||||
while (i--) {
|
||||
if (arr[i] === item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return arr.indexOf(item) != -1;
|
||||
}
|
||||
|
||||
function scriptHint(editor, _keywords, getToken) {
|
||||
// Find the token at the cursor
|
||||
var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
|
||||
// If it's not a 'word-style' token, ignore the token.
|
||||
|
||||
if (!/^[\w$_]*$/.test(token.string)) {
|
||||
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
||||
className: token.string == ":" ? "pig-type" : null};
|
||||
}
|
||||
|
||||
if (!context) var context = [];
|
||||
context.push(tprop);
|
||||
|
||||
var completionList = getCompletions(token, context);
|
||||
completionList = completionList.sort();
|
||||
//prevent autocomplete for last word, instead show dropdown with one word
|
||||
if(completionList.length == 1) {
|
||||
completionList.push(" ");
|
||||
}
|
||||
|
||||
return {list: completionList,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)};
|
||||
}
|
||||
|
||||
function pigHint(editor) {
|
||||
return scriptHint(editor, pigKeywordsU, function (e, cur) {return e.getTokenAt(cur);});
|
||||
}
|
||||
CodeMirror.pigHint = pigHint; // deprecated
|
||||
CodeMirror.registerHelper("hint", "pig", pigHint);
|
||||
|
||||
var pigKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
|
||||
+ "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
|
||||
+ "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
|
||||
+ "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
|
||||
+ "NEQ MATCHES TRUE FALSE";
|
||||
var pigKeywordsU = pigKeywords.split(" ");
|
||||
var pigKeywordsL = pigKeywords.toLowerCase().split(" ");
|
||||
|
||||
var pigTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP";
|
||||
var pigTypesU = pigTypes.split(" ");
|
||||
var pigTypesL = pigTypes.toLowerCase().split(" ");
|
||||
|
||||
var pigBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
|
||||
+ "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
|
||||
+ "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
|
||||
+ "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
|
||||
+ "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
|
||||
+ "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
|
||||
+ "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
|
||||
+ "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
|
||||
+ "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
|
||||
+ "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER";
|
||||
var pigBuiltinsU = pigBuiltins.split(" ").join("() ").split(" ");
|
||||
var pigBuiltinsL = pigBuiltins.toLowerCase().split(" ").join("() ").split(" ");
|
||||
var pigBuiltinsC = ("BagSize BinStorage Bloom BuildBloom ConstantSize CubeDimensions DoubleAbs "
|
||||
+ "DoubleAvg DoubleBase DoubleMax DoubleMin DoubleRound DoubleSum FloatAbs FloatAvg FloatMax "
|
||||
+ "FloatMin FloatRound FloatSum GenericInvoker IntAbs IntAvg IntMax IntMin IntSum "
|
||||
+ "InvokeForDouble InvokeForFloat InvokeForInt InvokeForLong InvokeForString Invoker "
|
||||
+ "IsEmpty JsonLoader JsonMetadata JsonStorage LongAbs LongAvg LongMax LongMin LongSum MapSize "
|
||||
+ "MonitoredUDF Nondeterministic OutputSchema PigStorage PigStreaming StringConcat StringMax "
|
||||
+ "StringMin StringSize TextLoader TupleSize Utf8StorageConverter").split(" ").join("() ").split(" ");
|
||||
|
||||
function getCompletions(token, context) {
|
||||
var found = [], start = token.string;
|
||||
function maybeAdd(str) {
|
||||
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
|
||||
}
|
||||
|
||||
function gatherCompletions(obj) {
|
||||
if(obj == ":") {
|
||||
forEach(pigTypesL, maybeAdd);
|
||||
}
|
||||
else {
|
||||
forEach(pigBuiltinsU, maybeAdd);
|
||||
forEach(pigBuiltinsL, maybeAdd);
|
||||
forEach(pigBuiltinsC, maybeAdd);
|
||||
forEach(pigTypesU, maybeAdd);
|
||||
forEach(pigTypesL, maybeAdd);
|
||||
forEach(pigKeywordsU, maybeAdd);
|
||||
forEach(pigKeywordsL, maybeAdd);
|
||||
}
|
||||
}
|
||||
|
||||
if (context) {
|
||||
// If this is a property, see if it belongs to some object we can
|
||||
// find in the current environment.
|
||||
var obj = context.pop(), base;
|
||||
|
||||
if (obj.type == "variable")
|
||||
base = obj.string;
|
||||
else if(obj.type == "variable-3")
|
||||
base = ":" + obj.string;
|
||||
|
||||
while (base != null && context.length)
|
||||
base = base[context.pop().string];
|
||||
if (base != null) gatherCompletions(base);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
})();
|
95
plugins/codemirror/codemirror/addon/hint/python-hint.js
vendored
Normal file
95
plugins/codemirror/codemirror/addon/hint/python-hint.js
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
(function () {
|
||||
function forEach(arr, f) {
|
||||
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
||||
}
|
||||
|
||||
function arrayContains(arr, item) {
|
||||
if (!Array.prototype.indexOf) {
|
||||
var i = arr.length;
|
||||
while (i--) {
|
||||
if (arr[i] === item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return arr.indexOf(item) != -1;
|
||||
}
|
||||
|
||||
function scriptHint(editor, _keywords, getToken) {
|
||||
// Find the token at the cursor
|
||||
var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
|
||||
// If it's not a 'word-style' token, ignore the token.
|
||||
|
||||
if (!/^[\w$_]*$/.test(token.string)) {
|
||||
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
||||
className: token.string == ":" ? "python-type" : null};
|
||||
}
|
||||
|
||||
if (!context) var context = [];
|
||||
context.push(tprop);
|
||||
|
||||
var completionList = getCompletions(token, context);
|
||||
completionList = completionList.sort();
|
||||
//prevent autocomplete for last word, instead show dropdown with one word
|
||||
if(completionList.length == 1) {
|
||||
completionList.push(" ");
|
||||
}
|
||||
|
||||
return {list: completionList,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)};
|
||||
}
|
||||
|
||||
function pythonHint(editor) {
|
||||
return scriptHint(editor, pythonKeywordsU, function (e, cur) {return e.getTokenAt(cur);});
|
||||
}
|
||||
CodeMirror.pythonHint = pythonHint; // deprecated
|
||||
CodeMirror.registerHelper("hint", "python", pythonHint);
|
||||
|
||||
var pythonKeywords = "and del from not while as elif global or with assert else if pass yield"
|
||||
+ "break except import print class exec in raise continue finally is return def for lambda try";
|
||||
var pythonKeywordsL = pythonKeywords.split(" ");
|
||||
var pythonKeywordsU = pythonKeywords.toUpperCase().split(" ");
|
||||
|
||||
var pythonBuiltins = "abs divmod input open staticmethod all enumerate int ord str "
|
||||
+ "any eval isinstance pow sum basestring execfile issubclass print super"
|
||||
+ "bin file iter property tuple bool filter len range type"
|
||||
+ "bytearray float list raw_input unichr callable format locals reduce unicode"
|
||||
+ "chr frozenset long reload vars classmethod getattr map repr xrange"
|
||||
+ "cmp globals max reversed zip compile hasattr memoryview round __import__"
|
||||
+ "complex hash min set apply delattr help next setattr buffer"
|
||||
+ "dict hex object slice coerce dir id oct sorted intern ";
|
||||
var pythonBuiltinsL = pythonBuiltins.split(" ").join("() ").split(" ");
|
||||
var pythonBuiltinsU = pythonBuiltins.toUpperCase().split(" ").join("() ").split(" ");
|
||||
|
||||
function getCompletions(token, context) {
|
||||
var found = [], start = token.string;
|
||||
function maybeAdd(str) {
|
||||
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
|
||||
}
|
||||
|
||||
function gatherCompletions(_obj) {
|
||||
forEach(pythonBuiltinsL, maybeAdd);
|
||||
forEach(pythonBuiltinsU, maybeAdd);
|
||||
forEach(pythonKeywordsL, maybeAdd);
|
||||
forEach(pythonKeywordsU, maybeAdd);
|
||||
}
|
||||
|
||||
if (context) {
|
||||
// If this is a property, see if it belongs to some object we can
|
||||
// find in the current environment.
|
||||
var obj = context.pop(), base;
|
||||
|
||||
if (obj.type == "variable")
|
||||
base = obj.string;
|
||||
else if(obj.type == "variable-3")
|
||||
base = ":" + obj.string;
|
||||
|
||||
while (base != null && context.length)
|
||||
base = base[context.pop().string];
|
||||
if (base != null) gatherCompletions(base);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
})();
|
38
plugins/codemirror/codemirror/addon/hint/show-hint.css
vendored
Normal file
38
plugins/codemirror/codemirror/addon/hint/show-hint.css
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
.CodeMirror-hints {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
list-style: none;
|
||||
|
||||
margin: 0;
|
||||
padding: 2px;
|
||||
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
border-radius: 3px;
|
||||
border: 1px solid silver;
|
||||
|
||||
background: white;
|
||||
font-size: 90%;
|
||||
font-family: monospace;
|
||||
|
||||
max-height: 20em;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.CodeMirror-hint {
|
||||
margin: 0;
|
||||
padding: 0 4px;
|
||||
border-radius: 2px;
|
||||
max-width: 19em;
|
||||
overflow: hidden;
|
||||
white-space: pre;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.CodeMirror-hint-active {
|
||||
background: #08f;
|
||||
color: white;
|
||||
}
|
286
plugins/codemirror/codemirror/addon/hint/show-hint.js
vendored
Normal file
286
plugins/codemirror/codemirror/addon/hint/show-hint.js
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
||||
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
||||
|
||||
CodeMirror.showHint = function(cm, getHints, options) {
|
||||
// We want a single cursor position.
|
||||
if (cm.somethingSelected()) return;
|
||||
if (getHints == null) getHints = cm.getHelper(cm.getCursor(), "hint");
|
||||
if (getHints == null) return;
|
||||
|
||||
if (cm.state.completionActive) cm.state.completionActive.close();
|
||||
|
||||
var completion = cm.state.completionActive = new Completion(cm, getHints, options || {});
|
||||
CodeMirror.signal(cm, "startCompletion", cm);
|
||||
if (completion.options.async)
|
||||
getHints(cm, function(hints) { completion.showHints(hints); }, completion.options);
|
||||
else
|
||||
return completion.showHints(getHints(cm, completion.options));
|
||||
};
|
||||
|
||||
function Completion(cm, getHints, options) {
|
||||
this.cm = cm;
|
||||
this.getHints = getHints;
|
||||
this.options = options;
|
||||
this.widget = this.onClose = null;
|
||||
}
|
||||
|
||||
Completion.prototype = {
|
||||
close: function() {
|
||||
if (!this.active()) return;
|
||||
this.cm.state.completionActive = null;
|
||||
|
||||
if (this.widget) this.widget.close();
|
||||
if (this.onClose) this.onClose();
|
||||
CodeMirror.signal(this.cm, "endCompletion", this.cm);
|
||||
},
|
||||
|
||||
active: function() {
|
||||
return this.cm.state.completionActive == this;
|
||||
},
|
||||
|
||||
pick: function(data, i) {
|
||||
var completion = data.list[i];
|
||||
if (completion.hint) completion.hint(this.cm, data, completion);
|
||||
else this.cm.replaceRange(getText(completion), data.from, data.to);
|
||||
this.close();
|
||||
},
|
||||
|
||||
showHints: function(data) {
|
||||
if (!data || !data.list.length || !this.active()) return this.close();
|
||||
|
||||
if (this.options.completeSingle != false && data.list.length == 1)
|
||||
this.pick(data, 0);
|
||||
else
|
||||
this.showWidget(data);
|
||||
},
|
||||
|
||||
showWidget: function(data) {
|
||||
this.widget = new Widget(this, data);
|
||||
CodeMirror.signal(data, "shown");
|
||||
|
||||
var debounce = null, completion = this, finished;
|
||||
var closeOn = this.options.closeCharacters || /[\s()\[\]{};:>,]/;
|
||||
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
|
||||
|
||||
function done() {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
completion.close();
|
||||
completion.cm.off("cursorActivity", activity);
|
||||
if (data) CodeMirror.signal(data, "close");
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (finished) return;
|
||||
CodeMirror.signal(data, "update");
|
||||
if (completion.options.async)
|
||||
completion.getHints(completion.cm, finishUpdate, completion.options);
|
||||
else
|
||||
finishUpdate(completion.getHints(completion.cm, completion.options));
|
||||
}
|
||||
function finishUpdate(data_) {
|
||||
data = data_;
|
||||
if (finished) return;
|
||||
if (!data || !data.list.length) return done();
|
||||
completion.widget = new Widget(completion, data);
|
||||
}
|
||||
|
||||
function activity() {
|
||||
clearTimeout(debounce);
|
||||
var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line);
|
||||
if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch ||
|
||||
pos.ch < startPos.ch || completion.cm.somethingSelected() ||
|
||||
(pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) {
|
||||
completion.close();
|
||||
} else {
|
||||
debounce = setTimeout(update, 170);
|
||||
if (completion.widget) completion.widget.close();
|
||||
}
|
||||
}
|
||||
this.cm.on("cursorActivity", activity);
|
||||
this.onClose = done;
|
||||
}
|
||||
};
|
||||
|
||||
function getText(completion) {
|
||||
if (typeof completion == "string") return completion;
|
||||
else return completion.text;
|
||||
}
|
||||
|
||||
function buildKeyMap(options, handle) {
|
||||
var baseMap = {
|
||||
Up: function() {handle.moveFocus(-1);},
|
||||
Down: function() {handle.moveFocus(1);},
|
||||
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
|
||||
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
|
||||
Home: function() {handle.setFocus(0);},
|
||||
End: function() {handle.setFocus(handle.length - 1);},
|
||||
Enter: handle.pick,
|
||||
Tab: handle.pick,
|
||||
Esc: handle.close
|
||||
};
|
||||
var ourMap = options.customKeys ? {} : baseMap;
|
||||
function addBinding(key, val) {
|
||||
var bound;
|
||||
if (typeof val != "string")
|
||||
bound = function(cm) { return val(cm, handle); };
|
||||
// This mechanism is deprecated
|
||||
else if (baseMap.hasOwnProperty(val))
|
||||
bound = baseMap[val];
|
||||
else
|
||||
bound = val;
|
||||
ourMap[key] = bound;
|
||||
}
|
||||
if (options.customKeys)
|
||||
for (var key in options.customKeys) if (options.customKeys.hasOwnProperty(key))
|
||||
addBinding(key, options.customKeys[key]);
|
||||
if (options.extraKeys)
|
||||
for (var key in options.extraKeys) if (options.extraKeys.hasOwnProperty(key))
|
||||
addBinding(key, options.extraKeys[key]);
|
||||
return ourMap;
|
||||
}
|
||||
|
||||
function getHintElement(stopAt, el) {
|
||||
while (el && el != stopAt) {
|
||||
if (el.nodeName.toUpperCase() === "LI") return el;
|
||||
el = el.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
function Widget(completion, data) {
|
||||
this.completion = completion;
|
||||
this.data = data;
|
||||
var widget = this, cm = completion.cm, options = completion.options;
|
||||
|
||||
var hints = this.hints = document.createElement("ul");
|
||||
hints.className = "CodeMirror-hints";
|
||||
this.selectedHint = options.getDefaultSelection ? options.getDefaultSelection(cm,options,data) : 0;
|
||||
|
||||
var completions = data.list;
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
|
||||
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
|
||||
if (cur.className != null) className = cur.className + " " + className;
|
||||
elt.className = className;
|
||||
if (cur.render) cur.render(elt, data, cur);
|
||||
else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
|
||||
elt.hintId = i;
|
||||
}
|
||||
|
||||
var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
|
||||
var left = pos.left, top = pos.bottom, below = true;
|
||||
hints.style.left = left + "px";
|
||||
hints.style.top = top + "px";
|
||||
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
||||
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
|
||||
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
||||
(options.container || document.body).appendChild(hints);
|
||||
var box = hints.getBoundingClientRect();
|
||||
var overlapX = box.right - winW, overlapY = box.bottom - winH;
|
||||
if (overlapX > 0) {
|
||||
if (box.right - box.left > winW) {
|
||||
hints.style.width = (winW - 5) + "px";
|
||||
overlapX -= (box.right - box.left) - winW;
|
||||
}
|
||||
hints.style.left = (left = pos.left - overlapX) + "px";
|
||||
}
|
||||
if (overlapY > 0) {
|
||||
var height = box.bottom - box.top;
|
||||
if (box.top - (pos.bottom - pos.top) - height > 0) {
|
||||
overlapY = height + (pos.bottom - pos.top);
|
||||
below = false;
|
||||
} else if (height > winH) {
|
||||
hints.style.height = (winH - 5) + "px";
|
||||
overlapY -= height - winH;
|
||||
}
|
||||
hints.style.top = (top = pos.bottom - overlapY) + "px";
|
||||
}
|
||||
|
||||
cm.addKeyMap(this.keyMap = buildKeyMap(options, {
|
||||
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
||||
setFocus: function(n) { widget.changeActive(n); },
|
||||
menuSize: function() { return widget.screenAmount(); },
|
||||
length: completions.length,
|
||||
close: function() { completion.close(); },
|
||||
pick: function() { widget.pick(); }
|
||||
}));
|
||||
|
||||
if (options.closeOnUnfocus !== false) {
|
||||
var closingOnBlur;
|
||||
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
||||
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
||||
}
|
||||
|
||||
var startScroll = cm.getScrollInfo();
|
||||
cm.on("scroll", this.onScroll = function() {
|
||||
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
|
||||
var newTop = top + startScroll.top - curScroll.top;
|
||||
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
|
||||
if (!below) point += hints.offsetHeight;
|
||||
if (point <= editor.top || point >= editor.bottom) return completion.close();
|
||||
hints.style.top = newTop + "px";
|
||||
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "dblclick", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "click", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) widget.changeActive(t.hintId);
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "mousedown", function() {
|
||||
setTimeout(function(){cm.focus();}, 20);
|
||||
});
|
||||
|
||||
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget.prototype = {
|
||||
close: function() {
|
||||
if (this.completion.widget != this) return;
|
||||
this.completion.widget = null;
|
||||
this.hints.parentNode.removeChild(this.hints);
|
||||
this.completion.cm.removeKeyMap(this.keyMap);
|
||||
|
||||
var cm = this.completion.cm;
|
||||
if (this.completion.options.closeOnUnfocus !== false) {
|
||||
cm.off("blur", this.onBlur);
|
||||
cm.off("focus", this.onFocus);
|
||||
}
|
||||
cm.off("scroll", this.onScroll);
|
||||
},
|
||||
|
||||
pick: function() {
|
||||
this.completion.pick(this.data, this.selectedHint);
|
||||
},
|
||||
|
||||
changeActive: function(i, avoidWrap) {
|
||||
if (i >= this.data.list.length)
|
||||
i = avoidWrap ? this.data.list.length - 1 : 0;
|
||||
else if (i < 0)
|
||||
i = avoidWrap ? 0 : this.data.list.length - 1;
|
||||
if (this.selectedHint == i) return;
|
||||
var node = this.hints.childNodes[this.selectedHint];
|
||||
node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
|
||||
node = this.hints.childNodes[this.selectedHint = i];
|
||||
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
|
||||
if (node.offsetTop < this.hints.scrollTop)
|
||||
this.hints.scrollTop = node.offsetTop - 3;
|
||||
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
|
||||
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
|
||||
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
|
||||
},
|
||||
|
||||
screenAmount: function() {
|
||||
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
|
||||
}
|
||||
};
|
||||
})();
|
105
plugins/codemirror/codemirror/addon/hint/sql-hint.js
vendored
Normal file
105
plugins/codemirror/codemirror/addon/hint/sql-hint.js
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var tables;
|
||||
var keywords;
|
||||
|
||||
function getKeywords(editor) {
|
||||
var mode = editor.doc.modeOption;
|
||||
if(mode === "sql") mode = "text/x-sql";
|
||||
return CodeMirror.resolveMode(mode).keywords;
|
||||
}
|
||||
|
||||
function match(string, word) {
|
||||
var len = string.length;
|
||||
var sub = word.substr(0, len);
|
||||
return string.toUpperCase() === sub.toUpperCase();
|
||||
}
|
||||
|
||||
function addMatches(result, search, wordlist, formatter) {
|
||||
for(var word in wordlist) {
|
||||
if(!wordlist.hasOwnProperty(word)) continue;
|
||||
if(Array.isArray(wordlist)) {
|
||||
word = wordlist[word];
|
||||
}
|
||||
if(match(search, word)) {
|
||||
result.push(formatter(word));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function columnCompletion(result, editor) {
|
||||
var cur = editor.getCursor();
|
||||
var token = editor.getTokenAt(cur);
|
||||
var string = token.string.substr(1);
|
||||
var prevCur = CodeMirror.Pos(cur.line, token.start);
|
||||
var table = editor.getTokenAt(prevCur).string;
|
||||
var columns = tables[table];
|
||||
if(!columns) {
|
||||
table = findTableByAlias(table, editor);
|
||||
}
|
||||
columns = tables[table];
|
||||
if(!columns) {
|
||||
return;
|
||||
}
|
||||
addMatches(result, string, columns,
|
||||
function(w) {return "." + w;});
|
||||
}
|
||||
|
||||
function eachWord(line, f) {
|
||||
var words = line.text.split(" ");
|
||||
for(var i = 0; i < words.length; i++) {
|
||||
f(words[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Tries to find possible table name from alias.
|
||||
function findTableByAlias(alias, editor) {
|
||||
var aliasUpperCase = alias.toUpperCase();
|
||||
var previousWord = "";
|
||||
var table = "";
|
||||
|
||||
editor.eachLine(function(line) {
|
||||
eachWord(line, function(word) {
|
||||
var wordUpperCase = word.toUpperCase();
|
||||
if(wordUpperCase === aliasUpperCase) {
|
||||
if(tables.hasOwnProperty(previousWord)) {
|
||||
table = previousWord;
|
||||
}
|
||||
}
|
||||
if(wordUpperCase !== "AS") {
|
||||
previousWord = word;
|
||||
}
|
||||
});
|
||||
});
|
||||
return table;
|
||||
}
|
||||
|
||||
function sqlHint(editor, options) {
|
||||
tables = (options && options.tables) || {};
|
||||
keywords = keywords || getKeywords(editor);
|
||||
var cur = editor.getCursor();
|
||||
var token = editor.getTokenAt(cur);
|
||||
|
||||
var result = [];
|
||||
|
||||
var search = token.string.trim();
|
||||
|
||||
addMatches(result, search, keywords,
|
||||
function(w) {return w.toUpperCase();});
|
||||
|
||||
addMatches(result, search, tables,
|
||||
function(w) {return w;});
|
||||
|
||||
if(search.lastIndexOf('.') === 0) {
|
||||
columnCompletion(result, editor);
|
||||
}
|
||||
|
||||
return {
|
||||
list: result,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)
|
||||
};
|
||||
}
|
||||
CodeMirror.registerHelper("hint", "sql", sqlHint);
|
||||
})();
|
69
plugins/codemirror/codemirror/addon/hint/xml-hint.js
vendored
Normal file
69
plugins/codemirror/codemirror/addon/hint/xml-hint.js
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function getHints(cm, options) {
|
||||
var tags = options && options.schemaInfo;
|
||||
var quote = (options && options.quoteChar) || '"';
|
||||
if (!tags) return;
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
|
||||
if (inner.mode.name != "xml") return;
|
||||
var result = [], replaceToken = false, prefix;
|
||||
var isTag = token.string.charAt(0) == "<";
|
||||
if (!inner.state.tagName || isTag) { // Tag completion
|
||||
if (isTag) {
|
||||
prefix = token.string.slice(1);
|
||||
replaceToken = true;
|
||||
}
|
||||
var cx = inner.state.context, curTag = cx && tags[cx.tagName];
|
||||
var childList = cx ? curTag && curTag.children : tags["!top"];
|
||||
if (childList) {
|
||||
for (var i = 0; i < childList.length; ++i) if (!prefix || childList[i].indexOf(prefix) == 0)
|
||||
result.push("<" + childList[i]);
|
||||
} else {
|
||||
for (var name in tags) if (tags.hasOwnProperty(name) && name != "!top" && (!prefix || name.indexOf(prefix) == 0))
|
||||
result.push("<" + name);
|
||||
}
|
||||
if (cx && (!prefix || ("/" + cx.tagName).indexOf(prefix) == 0))
|
||||
result.push("</" + cx.tagName + ">");
|
||||
} else {
|
||||
// Attribute completion
|
||||
var curTag = tags[inner.state.tagName], attrs = curTag && curTag.attrs;
|
||||
if (!attrs) return;
|
||||
if (token.type == "string" || token.string == "=") { // A value
|
||||
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
|
||||
Pos(cur.line, token.type == "string" ? token.start : token.end));
|
||||
var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/), atValues;
|
||||
if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
|
||||
if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
|
||||
if (token.type == "string") {
|
||||
prefix = token.string;
|
||||
if (/['"]/.test(token.string.charAt(0))) {
|
||||
quote = token.string.charAt(0);
|
||||
prefix = token.string.slice(1);
|
||||
}
|
||||
replaceToken = true;
|
||||
}
|
||||
for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].indexOf(prefix) == 0)
|
||||
result.push(quote + atValues[i] + quote);
|
||||
} else { // An attribute name
|
||||
if (token.type == "attribute") {
|
||||
prefix = token.string;
|
||||
replaceToken = true;
|
||||
}
|
||||
for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.indexOf(prefix) == 0))
|
||||
result.push(attr);
|
||||
}
|
||||
}
|
||||
return {
|
||||
list: result,
|
||||
from: replaceToken ? Pos(cur.line, token.start) : cur,
|
||||
to: replaceToken ? Pos(cur.line, token.end) : cur
|
||||
};
|
||||
}
|
||||
|
||||
CodeMirror.xmlHint = getHints; // deprecated
|
||||
CodeMirror.registerHelper("hint", "xml", getHints);
|
||||
})();
|
27
plugins/codemirror/codemirror/addon/lint/coffeescript-lint.js
vendored
Normal file
27
plugins/codemirror/codemirror/addon/lint/coffeescript-lint.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js
|
||||
|
||||
// declare global: coffeelint
|
||||
|
||||
CodeMirror.registerHelper("lint", "coffeescript", function(text) {
|
||||
var found = [];
|
||||
var parseError = function(err) {
|
||||
var loc = err.lineNumber;
|
||||
found.push({from: CodeMirror.Pos(loc-1, 0),
|
||||
to: CodeMirror.Pos(loc, 0),
|
||||
severity: err.level,
|
||||
message: err.message});
|
||||
};
|
||||
try {
|
||||
var res = coffeelint.lint(text);
|
||||
for(var i = 0; i < res.length; i++) {
|
||||
parseError(res[i]);
|
||||
}
|
||||
} catch(e) {
|
||||
found.push({from: CodeMirror.Pos(e.location.first_line, 0),
|
||||
to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
|
||||
severity: 'error',
|
||||
message: e.message});
|
||||
}
|
||||
return found;
|
||||
});
|
||||
CodeMirror.coffeeValidator = CodeMirror.lint.coffeescript; // deprecated
|
19
plugins/codemirror/codemirror/addon/lint/css-lint.js
vendored
Normal file
19
plugins/codemirror/codemirror/addon/lint/css-lint.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Depends on csslint.js from https://github.com/stubbornella/csslint
|
||||
|
||||
// declare global: CSSLint
|
||||
|
||||
CodeMirror.registerHelper("lint", "css", function(text) {
|
||||
var found = [];
|
||||
var results = CSSLint.verify(text), messages = results.messages, message = null;
|
||||
for ( var i = 0; i < messages.length; i++) {
|
||||
message = messages[i];
|
||||
var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
|
||||
found.push({
|
||||
from: CodeMirror.Pos(startLine, startCol),
|
||||
to: CodeMirror.Pos(endLine, endCol),
|
||||
message: message.message,
|
||||
severity : message.type
|
||||
});
|
||||
}
|
||||
return found;
|
||||
});
|
126
plugins/codemirror/codemirror/addon/lint/javascript-lint.js
vendored
Normal file
126
plugins/codemirror/codemirror/addon/lint/javascript-lint.js
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
// declare global: JSHINT
|
||||
|
||||
var bogus = [ "Dangerous comment" ];
|
||||
|
||||
var warnings = [ [ "Expected '{'",
|
||||
"Statement body should be inside '{ }' braces." ] ];
|
||||
|
||||
var errors = [ "Missing semicolon", "Extra comma", "Missing property name",
|
||||
"Unmatched ", " and instead saw", " is not defined",
|
||||
"Unclosed string", "Stopping, unable to continue" ];
|
||||
|
||||
function validator(text, options) {
|
||||
JSHINT(text, options);
|
||||
var errors = JSHINT.data().errors, result = [];
|
||||
if (errors) parseErrors(errors, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("lint", "javascript", validator);
|
||||
CodeMirror.javascriptValidator = CodeMirror.lint.javascript; // deprecated
|
||||
|
||||
function cleanup(error) {
|
||||
// All problems are warnings by default
|
||||
fixWith(error, warnings, "warning", true);
|
||||
fixWith(error, errors, "error");
|
||||
|
||||
return isBogus(error) ? null : error;
|
||||
}
|
||||
|
||||
function fixWith(error, fixes, severity, force) {
|
||||
var description, fix, find, replace, found;
|
||||
|
||||
description = error.description;
|
||||
|
||||
for ( var i = 0; i < fixes.length; i++) {
|
||||
fix = fixes[i];
|
||||
find = (typeof fix === "string" ? fix : fix[0]);
|
||||
replace = (typeof fix === "string" ? null : fix[1]);
|
||||
found = description.indexOf(find) !== -1;
|
||||
|
||||
if (force || found) {
|
||||
error.severity = severity;
|
||||
}
|
||||
if (found && replace) {
|
||||
error.description = replace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isBogus(error) {
|
||||
var description = error.description;
|
||||
for ( var i = 0; i < bogus.length; i++) {
|
||||
if (description.indexOf(bogus[i]) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseErrors(errors, output) {
|
||||
for ( var i = 0; i < errors.length; i++) {
|
||||
var error = errors[i];
|
||||
if (error) {
|
||||
var linetabpositions, index;
|
||||
|
||||
linetabpositions = [];
|
||||
|
||||
// This next block is to fix a problem in jshint. Jshint
|
||||
// replaces
|
||||
// all tabs with spaces then performs some checks. The error
|
||||
// positions (character/space) are then reported incorrectly,
|
||||
// not taking the replacement step into account. Here we look
|
||||
// at the evidence line and try to adjust the character position
|
||||
// to the correct value.
|
||||
if (error.evidence) {
|
||||
// Tab positions are computed once per line and cached
|
||||
var tabpositions = linetabpositions[error.line];
|
||||
if (!tabpositions) {
|
||||
var evidence = error.evidence;
|
||||
tabpositions = [];
|
||||
// ugggh phantomjs does not like this
|
||||
// forEachChar(evidence, function(item, index) {
|
||||
Array.prototype.forEach.call(evidence, function(item,
|
||||
index) {
|
||||
if (item === '\t') {
|
||||
// First col is 1 (not 0) to match error
|
||||
// positions
|
||||
tabpositions.push(index + 1);
|
||||
}
|
||||
});
|
||||
linetabpositions[error.line] = tabpositions;
|
||||
}
|
||||
if (tabpositions.length > 0) {
|
||||
var pos = error.character;
|
||||
tabpositions.forEach(function(tabposition) {
|
||||
if (pos > tabposition) pos -= 1;
|
||||
});
|
||||
error.character = pos;
|
||||
}
|
||||
}
|
||||
|
||||
var start = error.character - 1, end = start + 1;
|
||||
if (error.evidence) {
|
||||
index = error.evidence.substring(start).search(/.\b/);
|
||||
if (index > -1) {
|
||||
end += index;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert to format expected by validation service
|
||||
error.description = error.reason;// + "(jshint)";
|
||||
error.start = error.character;
|
||||
error.end = end;
|
||||
error = cleanup(error);
|
||||
|
||||
if (error)
|
||||
output.push({message: error.description,
|
||||
severity: error.severity,
|
||||
from: CodeMirror.Pos(error.line - 1, start),
|
||||
to: CodeMirror.Pos(error.line - 1, end)});
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
17
plugins/codemirror/codemirror/addon/lint/json-lint.js
vendored
Normal file
17
plugins/codemirror/codemirror/addon/lint/json-lint.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// Depends on jsonlint.js from https://github.com/zaach/jsonlint
|
||||
|
||||
// declare global: jsonlint
|
||||
|
||||
CodeMirror.registerHelper("lint", "json", function(text) {
|
||||
var found = [];
|
||||
jsonlint.parseError = function(str, hash) {
|
||||
var loc = hash.loc;
|
||||
found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
||||
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
||||
message: str});
|
||||
};
|
||||
try { jsonlint.parse(text); }
|
||||
catch(e) {}
|
||||
return found;
|
||||
});
|
||||
CodeMirror.jsonValidator = CodeMirror.lint.json; // deprecated
|
73
plugins/codemirror/codemirror/addon/lint/lint.css
vendored
Normal file
73
plugins/codemirror/codemirror/addon/lint/lint.css
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/* The lint marker gutter */
|
||||
.CodeMirror-lint-markers {
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.CodeMirror-lint-tooltip {
|
||||
background-color: infobackground;
|
||||
border: 1px solid black;
|
||||
border-radius: 4px 4px 4px 4px;
|
||||
color: infotext;
|
||||
font-family: monospace;
|
||||
font-size: 10pt;
|
||||
overflow: hidden;
|
||||
padding: 2px 5px;
|
||||
position: fixed;
|
||||
white-space: pre;
|
||||
white-space: pre-wrap;
|
||||
z-index: 100;
|
||||
max-width: 600px;
|
||||
opacity: 0;
|
||||
transition: opacity .4s;
|
||||
-moz-transition: opacity .4s;
|
||||
-webkit-transition: opacity .4s;
|
||||
-o-transition: opacity .4s;
|
||||
-ms-transition: opacity .4s;
|
||||
}
|
||||
|
||||
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
|
||||
background-position: left bottom;
|
||||
background-repeat: repeat-x;
|
||||
}
|
||||
|
||||
.CodeMirror-lint-mark-error {
|
||||
background-image:
|
||||
url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==")
|
||||
;
|
||||
}
|
||||
|
||||
.CodeMirror-lint-mark-warning {
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
|
||||
}
|
||||
|
||||
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
|
||||
background-position: center center;
|
||||
background-repeat: no-repeat;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
|
||||
padding-left: 18px;
|
||||
background-position: top left;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
|
||||
}
|
||||
|
||||
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
|
||||
}
|
||||
|
||||
.CodeMirror-lint-marker-multiple {
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right bottom;
|
||||
width: 100%; height: 100%;
|
||||
}
|
203
plugins/codemirror/codemirror/addon/lint/lint.js
vendored
Normal file
203
plugins/codemirror/codemirror/addon/lint/lint.js
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
var GUTTER_ID = "CodeMirror-lint-markers";
|
||||
var SEVERITIES = /^(?:error|warning)$/;
|
||||
|
||||
function showTooltip(e, content) {
|
||||
var tt = document.createElement("div");
|
||||
tt.className = "CodeMirror-lint-tooltip";
|
||||
tt.appendChild(content.cloneNode(true));
|
||||
document.body.appendChild(tt);
|
||||
|
||||
function position(e) {
|
||||
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
|
||||
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
|
||||
tt.style.left = (e.clientX + 5) + "px";
|
||||
}
|
||||
CodeMirror.on(document, "mousemove", position);
|
||||
position(e);
|
||||
if (tt.style.opacity != null) tt.style.opacity = 1;
|
||||
return tt;
|
||||
}
|
||||
function rm(elt) {
|
||||
if (elt.parentNode) elt.parentNode.removeChild(elt);
|
||||
}
|
||||
function hideTooltip(tt) {
|
||||
if (!tt.parentNode) return;
|
||||
if (tt.style.opacity == null) rm(tt);
|
||||
tt.style.opacity = 0;
|
||||
setTimeout(function() { rm(tt); }, 600);
|
||||
}
|
||||
|
||||
function showTooltipFor(e, content, node) {
|
||||
var tooltip = showTooltip(e, content);
|
||||
function hide() {
|
||||
CodeMirror.off(node, "mouseout", hide);
|
||||
if (tooltip) { hideTooltip(tooltip); tooltip = null; }
|
||||
}
|
||||
var poll = setInterval(function() {
|
||||
if (tooltip) for (var n = node;; n = n.parentNode) {
|
||||
if (n == document.body) return;
|
||||
if (!n) { hide(); break; }
|
||||
}
|
||||
if (!tooltip) return clearInterval(poll);
|
||||
}, 400);
|
||||
CodeMirror.on(node, "mouseout", hide);
|
||||
}
|
||||
|
||||
function LintState(cm, options, hasGutter) {
|
||||
this.marked = [];
|
||||
this.options = options;
|
||||
this.timeout = null;
|
||||
this.hasGutter = hasGutter;
|
||||
this.onMouseOver = function(e) { onMouseOver(cm, e); };
|
||||
}
|
||||
|
||||
function parseOptions(cm, options) {
|
||||
if (options instanceof Function) return {getAnnotations: options};
|
||||
if (!options || options === true) options = {};
|
||||
if (!options.getAnnotations) options.getAnnotations = cm.getHelper(CodeMirror.Pos(0, 0), "lint");
|
||||
if (!options.getAnnotations) throw new Error("Required option 'getAnnotations' missing (lint addon)");
|
||||
return options;
|
||||
}
|
||||
|
||||
function clearMarks(cm) {
|
||||
var state = cm.state.lint;
|
||||
if (state.hasGutter) cm.clearGutter(GUTTER_ID);
|
||||
for (var i = 0; i < state.marked.length; ++i)
|
||||
state.marked[i].clear();
|
||||
state.marked.length = 0;
|
||||
}
|
||||
|
||||
function makeMarker(labels, severity, multiple, tooltips) {
|
||||
var marker = document.createElement("div"), inner = marker;
|
||||
marker.className = "CodeMirror-lint-marker-" + severity;
|
||||
if (multiple) {
|
||||
inner = marker.appendChild(document.createElement("div"));
|
||||
inner.className = "CodeMirror-lint-marker-multiple";
|
||||
}
|
||||
|
||||
if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
|
||||
showTooltipFor(e, labels, inner);
|
||||
});
|
||||
|
||||
return marker;
|
||||
}
|
||||
|
||||
function getMaxSeverity(a, b) {
|
||||
if (a == "error") return a;
|
||||
else return b;
|
||||
}
|
||||
|
||||
function groupByLine(annotations) {
|
||||
var lines = [];
|
||||
for (var i = 0; i < annotations.length; ++i) {
|
||||
var ann = annotations[i], line = ann.from.line;
|
||||
(lines[line] || (lines[line] = [])).push(ann);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
function annotationTooltip(ann) {
|
||||
var severity = ann.severity;
|
||||
if (!SEVERITIES.test(severity)) severity = "error";
|
||||
var tip = document.createElement("div");
|
||||
tip.className = "CodeMirror-lint-message-" + severity;
|
||||
tip.appendChild(document.createTextNode(ann.message));
|
||||
return tip;
|
||||
}
|
||||
|
||||
function startLinting(cm) {
|
||||
var state = cm.state.lint, options = state.options;
|
||||
if (options.async)
|
||||
options.getAnnotations(cm, updateLinting, options);
|
||||
else
|
||||
updateLinting(cm, options.getAnnotations(cm.getValue(), options));
|
||||
}
|
||||
|
||||
function updateLinting(cm, annotationsNotSorted) {
|
||||
clearMarks(cm);
|
||||
var state = cm.state.lint, options = state.options;
|
||||
|
||||
var annotations = groupByLine(annotationsNotSorted);
|
||||
|
||||
for (var line = 0; line < annotations.length; ++line) {
|
||||
var anns = annotations[line];
|
||||
if (!anns) continue;
|
||||
|
||||
var maxSeverity = null;
|
||||
var tipLabel = state.hasGutter && document.createDocumentFragment();
|
||||
|
||||
for (var i = 0; i < anns.length; ++i) {
|
||||
var ann = anns[i];
|
||||
var severity = ann.severity;
|
||||
if (!SEVERITIES.test(severity)) severity = "error";
|
||||
maxSeverity = getMaxSeverity(maxSeverity, severity);
|
||||
|
||||
if (options.formatAnnotation) ann = options.formatAnnotation(ann);
|
||||
if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
|
||||
|
||||
if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
|
||||
className: "CodeMirror-lint-mark-" + severity,
|
||||
__annotation: ann
|
||||
}));
|
||||
}
|
||||
|
||||
if (state.hasGutter)
|
||||
cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
|
||||
state.options.tooltips));
|
||||
}
|
||||
if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
|
||||
}
|
||||
|
||||
function onChange(cm) {
|
||||
var state = cm.state.lint;
|
||||
clearTimeout(state.timeout);
|
||||
state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
|
||||
}
|
||||
|
||||
function popupSpanTooltip(ann, e) {
|
||||
var target = e.target || e.srcElement;
|
||||
showTooltipFor(e, annotationTooltip(ann), target);
|
||||
}
|
||||
|
||||
// When the mouseover fires, the cursor might not actually be over
|
||||
// the character itself yet. These pairs of x,y offsets are used to
|
||||
// probe a few nearby points when no suitable marked range is found.
|
||||
var nearby = [0, 0, 0, 5, 0, -5, 5, 0, -5, 0];
|
||||
|
||||
function onMouseOver(cm, e) {
|
||||
if (!/\bCodeMirror-lint-mark-/.test((e.target || e.srcElement).className)) return;
|
||||
for (var i = 0; i < nearby.length; i += 2) {
|
||||
var spans = cm.findMarksAt(cm.coordsChar({left: e.clientX + nearby[i],
|
||||
top: e.clientY + nearby[i + 1]}));
|
||||
for (var j = 0; j < spans.length; ++j) {
|
||||
var span = spans[j], ann = span.__annotation;
|
||||
if (ann) return popupSpanTooltip(ann, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function optionHandler(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init) {
|
||||
clearMarks(cm);
|
||||
cm.off("change", onChange);
|
||||
CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
|
||||
delete cm.state.lint;
|
||||
}
|
||||
|
||||
if (val) {
|
||||
var gutters = cm.getOption("gutters"), hasLintGutter = false;
|
||||
for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
|
||||
var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
|
||||
cm.on("change", onChange);
|
||||
if (state.options.tooltips != false)
|
||||
CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
|
||||
|
||||
startLinting(cm);
|
||||
}
|
||||
}
|
||||
|
||||
CodeMirror.defineOption("lintWith", false, optionHandler); // deprecated
|
||||
CodeMirror.defineOption("lint", false, optionHandler); // deprecated
|
||||
})();
|
50
plugins/codemirror/codemirror/addon/merge/dep/diff_match_patch.js
vendored
Normal file
50
plugins/codemirror/codemirror/addon/merge/dep/diff_match_patch.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// From https://code.google.com/p/google-diff-match-patch/ , licensed under the Apache License 2.0
|
||||
(function(){function diff_match_patch(){this.Diff_Timeout=1;this.Diff_EditCost=4;this.Match_Threshold=0.5;this.Match_Distance=1E3;this.Patch_DeleteThreshold=0.5;this.Patch_Margin=4;this.Match_MaxBits=32}
|
||||
diff_match_patch.prototype.diff_main=function(a,b,c,d){"undefined"==typeof d&&(d=0>=this.Diff_Timeout?Number.MAX_VALUE:(new Date).getTime()+1E3*this.Diff_Timeout);if(null==a||null==b)throw Error("Null input. (diff_main)");if(a==b)return a?[[0,a]]:[];"undefined"==typeof c&&(c=!0);var e=c,f=this.diff_commonPrefix(a,b);c=a.substring(0,f);a=a.substring(f);b=b.substring(f);var f=this.diff_commonSuffix(a,b),g=a.substring(a.length-f);a=a.substring(0,a.length-f);b=b.substring(0,b.length-f);a=this.diff_compute_(a,
|
||||
b,e,d);c&&a.unshift([0,c]);g&&a.push([0,g]);this.diff_cleanupMerge(a);return a};
|
||||
diff_match_patch.prototype.diff_compute_=function(a,b,c,d){if(!a)return[[1,b]];if(!b)return[[-1,a]];var e=a.length>b.length?a:b,f=a.length>b.length?b:a,g=e.indexOf(f);return-1!=g?(c=[[1,e.substring(0,g)],[0,f],[1,e.substring(g+f.length)]],a.length>b.length&&(c[0][0]=c[2][0]=-1),c):1==f.length?[[-1,a],[1,b]]:(e=this.diff_halfMatch_(a,b))?(f=e[0],a=e[1],g=e[2],b=e[3],e=e[4],f=this.diff_main(f,g,c,d),c=this.diff_main(a,b,c,d),f.concat([[0,e]],c)):c&&100<a.length&&100<b.length?this.diff_lineMode_(a,b,
|
||||
d):this.diff_bisect_(a,b,d)};
|
||||
diff_match_patch.prototype.diff_lineMode_=function(a,b,c){var d=this.diff_linesToChars_(a,b);a=d.chars1;b=d.chars2;d=d.lineArray;a=this.diff_main(a,b,!1,c);this.diff_charsToLines_(a,d);this.diff_cleanupSemantic(a);a.push([0,""]);for(var e=d=b=0,f="",g="";b<a.length;){switch(a[b][0]){case 1:e++;g+=a[b][1];break;case -1:d++;f+=a[b][1];break;case 0:if(1<=d&&1<=e){a.splice(b-d-e,d+e);b=b-d-e;d=this.diff_main(f,g,!1,c);for(e=d.length-1;0<=e;e--)a.splice(b,0,d[e]);b+=d.length}d=e=0;g=f=""}b++}a.pop();return a};
|
||||
diff_match_patch.prototype.diff_bisect_=function(a,b,c){for(var d=a.length,e=b.length,f=Math.ceil((d+e)/2),g=f,h=2*f,j=Array(h),i=Array(h),k=0;k<h;k++)j[k]=-1,i[k]=-1;j[g+1]=0;i[g+1]=0;for(var k=d-e,q=0!=k%2,r=0,t=0,p=0,w=0,v=0;v<f&&!((new Date).getTime()>c);v++){for(var n=-v+r;n<=v-t;n+=2){var l=g+n,m;m=n==-v||n!=v&&j[l-1]<j[l+1]?j[l+1]:j[l-1]+1;for(var s=m-n;m<d&&s<e&&a.charAt(m)==b.charAt(s);)m++,s++;j[l]=m;if(m>d)t+=2;else if(s>e)r+=2;else if(q&&(l=g+k-n,0<=l&&l<h&&-1!=i[l])){var u=d-i[l];if(m>=
|
||||
u)return this.diff_bisectSplit_(a,b,m,s,c)}}for(n=-v+p;n<=v-w;n+=2){l=g+n;u=n==-v||n!=v&&i[l-1]<i[l+1]?i[l+1]:i[l-1]+1;for(m=u-n;u<d&&m<e&&a.charAt(d-u-1)==b.charAt(e-m-1);)u++,m++;i[l]=u;if(u>d)w+=2;else if(m>e)p+=2;else if(!q&&(l=g+k-n,0<=l&&(l<h&&-1!=j[l])&&(m=j[l],s=g+m-l,u=d-u,m>=u)))return this.diff_bisectSplit_(a,b,m,s,c)}}return[[-1,a],[1,b]]};
|
||||
diff_match_patch.prototype.diff_bisectSplit_=function(a,b,c,d,e){var f=a.substring(0,c),g=b.substring(0,d);a=a.substring(c);b=b.substring(d);f=this.diff_main(f,g,!1,e);e=this.diff_main(a,b,!1,e);return f.concat(e)};
|
||||
diff_match_patch.prototype.diff_linesToChars_=function(a,b){function c(a){for(var b="",c=0,f=-1,g=d.length;f<a.length-1;){f=a.indexOf("\n",c);-1==f&&(f=a.length-1);var r=a.substring(c,f+1),c=f+1;(e.hasOwnProperty?e.hasOwnProperty(r):void 0!==e[r])?b+=String.fromCharCode(e[r]):(b+=String.fromCharCode(g),e[r]=g,d[g++]=r)}return b}var d=[],e={};d[0]="";var f=c(a),g=c(b);return{chars1:f,chars2:g,lineArray:d}};
|
||||
diff_match_patch.prototype.diff_charsToLines_=function(a,b){for(var c=0;c<a.length;c++){for(var d=a[c][1],e=[],f=0;f<d.length;f++)e[f]=b[d.charCodeAt(f)];a[c][1]=e.join("")}};diff_match_patch.prototype.diff_commonPrefix=function(a,b){if(!a||!b||a.charAt(0)!=b.charAt(0))return 0;for(var c=0,d=Math.min(a.length,b.length),e=d,f=0;c<e;)a.substring(f,e)==b.substring(f,e)?f=c=e:d=e,e=Math.floor((d-c)/2+c);return e};
|
||||
diff_match_patch.prototype.diff_commonSuffix=function(a,b){if(!a||!b||a.charAt(a.length-1)!=b.charAt(b.length-1))return 0;for(var c=0,d=Math.min(a.length,b.length),e=d,f=0;c<e;)a.substring(a.length-e,a.length-f)==b.substring(b.length-e,b.length-f)?f=c=e:d=e,e=Math.floor((d-c)/2+c);return e};
|
||||
diff_match_patch.prototype.diff_commonOverlap_=function(a,b){var c=a.length,d=b.length;if(0==c||0==d)return 0;c>d?a=a.substring(c-d):c<d&&(b=b.substring(0,c));c=Math.min(c,d);if(a==b)return c;for(var d=0,e=1;;){var f=a.substring(c-e),f=b.indexOf(f);if(-1==f)return d;e+=f;if(0==f||a.substring(c-e)==b.substring(0,e))d=e,e++}};
|
||||
diff_match_patch.prototype.diff_halfMatch_=function(a,b){function c(a,b,c){for(var d=a.substring(c,c+Math.floor(a.length/4)),e=-1,g="",h,j,n,l;-1!=(e=b.indexOf(d,e+1));){var m=f.diff_commonPrefix(a.substring(c),b.substring(e)),s=f.diff_commonSuffix(a.substring(0,c),b.substring(0,e));g.length<s+m&&(g=b.substring(e-s,e)+b.substring(e,e+m),h=a.substring(0,c-s),j=a.substring(c+m),n=b.substring(0,e-s),l=b.substring(e+m))}return 2*g.length>=a.length?[h,j,n,l,g]:null}if(0>=this.Diff_Timeout)return null;
|
||||
var d=a.length>b.length?a:b,e=a.length>b.length?b:a;if(4>d.length||2*e.length<d.length)return null;var f=this,g=c(d,e,Math.ceil(d.length/4)),d=c(d,e,Math.ceil(d.length/2)),h;if(!g&&!d)return null;h=d?g?g[4].length>d[4].length?g:d:d:g;var j;a.length>b.length?(g=h[0],d=h[1],e=h[2],j=h[3]):(e=h[0],j=h[1],g=h[2],d=h[3]);h=h[4];return[g,d,e,j,h]};
|
||||
diff_match_patch.prototype.diff_cleanupSemantic=function(a){for(var b=!1,c=[],d=0,e=null,f=0,g=0,h=0,j=0,i=0;f<a.length;)0==a[f][0]?(c[d++]=f,g=j,h=i,i=j=0,e=a[f][1]):(1==a[f][0]?j+=a[f][1].length:i+=a[f][1].length,e&&(e.length<=Math.max(g,h)&&e.length<=Math.max(j,i))&&(a.splice(c[d-1],0,[-1,e]),a[c[d-1]+1][0]=1,d--,d--,f=0<d?c[d-1]:-1,i=j=h=g=0,e=null,b=!0)),f++;b&&this.diff_cleanupMerge(a);this.diff_cleanupSemanticLossless(a);for(f=1;f<a.length;){if(-1==a[f-1][0]&&1==a[f][0]){b=a[f-1][1];c=a[f][1];
|
||||
d=this.diff_commonOverlap_(b,c);e=this.diff_commonOverlap_(c,b);if(d>=e){if(d>=b.length/2||d>=c.length/2)a.splice(f,0,[0,c.substring(0,d)]),a[f-1][1]=b.substring(0,b.length-d),a[f+1][1]=c.substring(d),f++}else if(e>=b.length/2||e>=c.length/2)a.splice(f,0,[0,b.substring(0,e)]),a[f-1][0]=1,a[f-1][1]=c.substring(0,c.length-e),a[f+1][0]=-1,a[f+1][1]=b.substring(e),f++;f++}f++}};
|
||||
diff_match_patch.prototype.diff_cleanupSemanticLossless=function(a){function b(a,b){if(!a||!b)return 6;var c=a.charAt(a.length-1),d=b.charAt(0),e=c.match(diff_match_patch.nonAlphaNumericRegex_),f=d.match(diff_match_patch.nonAlphaNumericRegex_),g=e&&c.match(diff_match_patch.whitespaceRegex_),h=f&&d.match(diff_match_patch.whitespaceRegex_),c=g&&c.match(diff_match_patch.linebreakRegex_),d=h&&d.match(diff_match_patch.linebreakRegex_),i=c&&a.match(diff_match_patch.blanklineEndRegex_),j=d&&b.match(diff_match_patch.blanklineStartRegex_);
|
||||
return i||j?5:c||d?4:e&&!g&&h?3:g||h?2:e||f?1:0}for(var c=1;c<a.length-1;){if(0==a[c-1][0]&&0==a[c+1][0]){var d=a[c-1][1],e=a[c][1],f=a[c+1][1],g=this.diff_commonSuffix(d,e);if(g)var h=e.substring(e.length-g),d=d.substring(0,d.length-g),e=h+e.substring(0,e.length-g),f=h+f;for(var g=d,h=e,j=f,i=b(d,e)+b(e,f);e.charAt(0)===f.charAt(0);){var d=d+e.charAt(0),e=e.substring(1)+f.charAt(0),f=f.substring(1),k=b(d,e)+b(e,f);k>=i&&(i=k,g=d,h=e,j=f)}a[c-1][1]!=g&&(g?a[c-1][1]=g:(a.splice(c-1,1),c--),a[c][1]=
|
||||
h,j?a[c+1][1]=j:(a.splice(c+1,1),c--))}c++}};diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;diff_match_patch.whitespaceRegex_=/\s/;diff_match_patch.linebreakRegex_=/[\r\n]/;diff_match_patch.blanklineEndRegex_=/\n\r?\n$/;diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/;
|
||||
diff_match_patch.prototype.diff_cleanupEfficiency=function(a){for(var b=!1,c=[],d=0,e=null,f=0,g=!1,h=!1,j=!1,i=!1;f<a.length;){if(0==a[f][0])a[f][1].length<this.Diff_EditCost&&(j||i)?(c[d++]=f,g=j,h=i,e=a[f][1]):(d=0,e=null),j=i=!1;else if(-1==a[f][0]?i=!0:j=!0,e&&(g&&h&&j&&i||e.length<this.Diff_EditCost/2&&3==g+h+j+i))a.splice(c[d-1],0,[-1,e]),a[c[d-1]+1][0]=1,d--,e=null,g&&h?(j=i=!0,d=0):(d--,f=0<d?c[d-1]:-1,j=i=!1),b=!0;f++}b&&this.diff_cleanupMerge(a)};
|
||||
diff_match_patch.prototype.diff_cleanupMerge=function(a){a.push([0,""]);for(var b=0,c=0,d=0,e="",f="",g;b<a.length;)switch(a[b][0]){case 1:d++;f+=a[b][1];b++;break;case -1:c++;e+=a[b][1];b++;break;case 0:1<c+d?(0!==c&&0!==d&&(g=this.diff_commonPrefix(f,e),0!==g&&(0<b-c-d&&0==a[b-c-d-1][0]?a[b-c-d-1][1]+=f.substring(0,g):(a.splice(0,0,[0,f.substring(0,g)]),b++),f=f.substring(g),e=e.substring(g)),g=this.diff_commonSuffix(f,e),0!==g&&(a[b][1]=f.substring(f.length-g)+a[b][1],f=f.substring(0,f.length-
|
||||
g),e=e.substring(0,e.length-g))),0===c?a.splice(b-d,c+d,[1,f]):0===d?a.splice(b-c,c+d,[-1,e]):a.splice(b-c-d,c+d,[-1,e],[1,f]),b=b-c-d+(c?1:0)+(d?1:0)+1):0!==b&&0==a[b-1][0]?(a[b-1][1]+=a[b][1],a.splice(b,1)):b++,c=d=0,f=e=""}""===a[a.length-1][1]&&a.pop();c=!1;for(b=1;b<a.length-1;)0==a[b-1][0]&&0==a[b+1][0]&&(a[b][1].substring(a[b][1].length-a[b-1][1].length)==a[b-1][1]?(a[b][1]=a[b-1][1]+a[b][1].substring(0,a[b][1].length-a[b-1][1].length),a[b+1][1]=a[b-1][1]+a[b+1][1],a.splice(b-1,1),c=!0):a[b][1].substring(0,
|
||||
a[b+1][1].length)==a[b+1][1]&&(a[b-1][1]+=a[b+1][1],a[b][1]=a[b][1].substring(a[b+1][1].length)+a[b+1][1],a.splice(b+1,1),c=!0)),b++;c&&this.diff_cleanupMerge(a)};diff_match_patch.prototype.diff_xIndex=function(a,b){var c=0,d=0,e=0,f=0,g;for(g=0;g<a.length;g++){1!==a[g][0]&&(c+=a[g][1].length);-1!==a[g][0]&&(d+=a[g][1].length);if(c>b)break;e=c;f=d}return a.length!=g&&-1===a[g][0]?f:f+(b-e)};
|
||||
diff_match_patch.prototype.diff_prettyHtml=function(a){for(var b=[],c=/&/g,d=/</g,e=/>/g,f=/\n/g,g=0;g<a.length;g++){var h=a[g][0],j=a[g][1],j=j.replace(c,"&").replace(d,"<").replace(e,">").replace(f,"¶<br>");switch(h){case 1:b[g]='<ins style="background:#e6ffe6;">'+j+"</ins>";break;case -1:b[g]='<del style="background:#ffe6e6;">'+j+"</del>";break;case 0:b[g]="<span>"+j+"</span>"}}return b.join("")};
|
||||
diff_match_patch.prototype.diff_text1=function(a){for(var b=[],c=0;c<a.length;c++)1!==a[c][0]&&(b[c]=a[c][1]);return b.join("")};diff_match_patch.prototype.diff_text2=function(a){for(var b=[],c=0;c<a.length;c++)-1!==a[c][0]&&(b[c]=a[c][1]);return b.join("")};diff_match_patch.prototype.diff_levenshtein=function(a){for(var b=0,c=0,d=0,e=0;e<a.length;e++){var f=a[e][0],g=a[e][1];switch(f){case 1:c+=g.length;break;case -1:d+=g.length;break;case 0:b+=Math.max(c,d),d=c=0}}return b+=Math.max(c,d)};
|
||||
diff_match_patch.prototype.diff_toDelta=function(a){for(var b=[],c=0;c<a.length;c++)switch(a[c][0]){case 1:b[c]="+"+encodeURI(a[c][1]);break;case -1:b[c]="-"+a[c][1].length;break;case 0:b[c]="="+a[c][1].length}return b.join("\t").replace(/%20/g," ")};
|
||||
diff_match_patch.prototype.diff_fromDelta=function(a,b){for(var c=[],d=0,e=0,f=b.split(/\t/g),g=0;g<f.length;g++){var h=f[g].substring(1);switch(f[g].charAt(0)){case "+":try{c[d++]=[1,decodeURI(h)]}catch(j){throw Error("Illegal escape in diff_fromDelta: "+h);}break;case "-":case "=":var i=parseInt(h,10);if(isNaN(i)||0>i)throw Error("Invalid number in diff_fromDelta: "+h);h=a.substring(e,e+=i);"="==f[g].charAt(0)?c[d++]=[0,h]:c[d++]=[-1,h];break;default:if(f[g])throw Error("Invalid diff operation in diff_fromDelta: "+
|
||||
f[g]);}}if(e!=a.length)throw Error("Delta length ("+e+") does not equal source text length ("+a.length+").");return c};diff_match_patch.prototype.match_main=function(a,b,c){if(null==a||null==b||null==c)throw Error("Null input. (match_main)");c=Math.max(0,Math.min(c,a.length));return a==b?0:a.length?a.substring(c,c+b.length)==b?c:this.match_bitap_(a,b,c):-1};
|
||||
diff_match_patch.prototype.match_bitap_=function(a,b,c){function d(a,d){var e=a/b.length,g=Math.abs(c-d);return!f.Match_Distance?g?1:e:e+g/f.Match_Distance}if(b.length>this.Match_MaxBits)throw Error("Pattern too long for this browser.");var e=this.match_alphabet_(b),f=this,g=this.Match_Threshold,h=a.indexOf(b,c);-1!=h&&(g=Math.min(d(0,h),g),h=a.lastIndexOf(b,c+b.length),-1!=h&&(g=Math.min(d(0,h),g)));for(var j=1<<b.length-1,h=-1,i,k,q=b.length+a.length,r,t=0;t<b.length;t++){i=0;for(k=q;i<k;)d(t,c+
|
||||
k)<=g?i=k:q=k,k=Math.floor((q-i)/2+i);q=k;i=Math.max(1,c-k+1);var p=Math.min(c+k,a.length)+b.length;k=Array(p+2);for(k[p+1]=(1<<t)-1;p>=i;p--){var w=e[a.charAt(p-1)];k[p]=0===t?(k[p+1]<<1|1)&w:(k[p+1]<<1|1)&w|((r[p+1]|r[p])<<1|1)|r[p+1];if(k[p]&j&&(w=d(t,p-1),w<=g))if(g=w,h=p-1,h>c)i=Math.max(1,2*c-h);else break}if(d(t+1,c)>g)break;r=k}return h};
|
||||
diff_match_patch.prototype.match_alphabet_=function(a){for(var b={},c=0;c<a.length;c++)b[a.charAt(c)]=0;for(c=0;c<a.length;c++)b[a.charAt(c)]|=1<<a.length-c-1;return b};
|
||||
diff_match_patch.prototype.patch_addContext_=function(a,b){if(0!=b.length){for(var c=b.substring(a.start2,a.start2+a.length1),d=0;b.indexOf(c)!=b.lastIndexOf(c)&&c.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)d+=this.Patch_Margin,c=b.substring(a.start2-d,a.start2+a.length1+d);d+=this.Patch_Margin;(c=b.substring(a.start2-d,a.start2))&&a.diffs.unshift([0,c]);(d=b.substring(a.start2+a.length1,a.start2+a.length1+d))&&a.diffs.push([0,d]);a.start1-=c.length;a.start2-=c.length;a.length1+=
|
||||
c.length+d.length;a.length2+=c.length+d.length}};
|
||||
diff_match_patch.prototype.patch_make=function(a,b,c){var d;if("string"==typeof a&&"string"==typeof b&&"undefined"==typeof c)d=a,b=this.diff_main(d,b,!0),2<b.length&&(this.diff_cleanupSemantic(b),this.diff_cleanupEfficiency(b));else if(a&&"object"==typeof a&&"undefined"==typeof b&&"undefined"==typeof c)b=a,d=this.diff_text1(b);else if("string"==typeof a&&b&&"object"==typeof b&&"undefined"==typeof c)d=a;else if("string"==typeof a&&"string"==typeof b&&c&&"object"==typeof c)d=a,b=c;else throw Error("Unknown call format to patch_make.");
|
||||
if(0===b.length)return[];c=[];a=new diff_match_patch.patch_obj;for(var e=0,f=0,g=0,h=d,j=0;j<b.length;j++){var i=b[j][0],k=b[j][1];!e&&0!==i&&(a.start1=f,a.start2=g);switch(i){case 1:a.diffs[e++]=b[j];a.length2+=k.length;d=d.substring(0,g)+k+d.substring(g);break;case -1:a.length1+=k.length;a.diffs[e++]=b[j];d=d.substring(0,g)+d.substring(g+k.length);break;case 0:k.length<=2*this.Patch_Margin&&e&&b.length!=j+1?(a.diffs[e++]=b[j],a.length1+=k.length,a.length2+=k.length):k.length>=2*this.Patch_Margin&&
|
||||
e&&(this.patch_addContext_(a,h),c.push(a),a=new diff_match_patch.patch_obj,e=0,h=d,f=g)}1!==i&&(f+=k.length);-1!==i&&(g+=k.length)}e&&(this.patch_addContext_(a,h),c.push(a));return c};diff_match_patch.prototype.patch_deepCopy=function(a){for(var b=[],c=0;c<a.length;c++){var d=a[c],e=new diff_match_patch.patch_obj;e.diffs=[];for(var f=0;f<d.diffs.length;f++)e.diffs[f]=d.diffs[f].slice();e.start1=d.start1;e.start2=d.start2;e.length1=d.length1;e.length2=d.length2;b[c]=e}return b};
|
||||
diff_match_patch.prototype.patch_apply=function(a,b){if(0==a.length)return[b,[]];a=this.patch_deepCopy(a);var c=this.patch_addPadding(a);b=c+b+c;this.patch_splitMax(a);for(var d=0,e=[],f=0;f<a.length;f++){var g=a[f].start2+d,h=this.diff_text1(a[f].diffs),j,i=-1;if(h.length>this.Match_MaxBits){if(j=this.match_main(b,h.substring(0,this.Match_MaxBits),g),-1!=j&&(i=this.match_main(b,h.substring(h.length-this.Match_MaxBits),g+h.length-this.Match_MaxBits),-1==i||j>=i))j=-1}else j=this.match_main(b,h,g);
|
||||
if(-1==j)e[f]=!1,d-=a[f].length2-a[f].length1;else if(e[f]=!0,d=j-g,g=-1==i?b.substring(j,j+h.length):b.substring(j,i+this.Match_MaxBits),h==g)b=b.substring(0,j)+this.diff_text2(a[f].diffs)+b.substring(j+h.length);else if(g=this.diff_main(h,g,!1),h.length>this.Match_MaxBits&&this.diff_levenshtein(g)/h.length>this.Patch_DeleteThreshold)e[f]=!1;else{this.diff_cleanupSemanticLossless(g);for(var h=0,k,i=0;i<a[f].diffs.length;i++){var q=a[f].diffs[i];0!==q[0]&&(k=this.diff_xIndex(g,h));1===q[0]?b=b.substring(0,
|
||||
j+k)+q[1]+b.substring(j+k):-1===q[0]&&(b=b.substring(0,j+k)+b.substring(j+this.diff_xIndex(g,h+q[1].length)));-1!==q[0]&&(h+=q[1].length)}}}b=b.substring(c.length,b.length-c.length);return[b,e]};
|
||||
diff_match_patch.prototype.patch_addPadding=function(a){for(var b=this.Patch_Margin,c="",d=1;d<=b;d++)c+=String.fromCharCode(d);for(d=0;d<a.length;d++)a[d].start1+=b,a[d].start2+=b;var d=a[0],e=d.diffs;if(0==e.length||0!=e[0][0])e.unshift([0,c]),d.start1-=b,d.start2-=b,d.length1+=b,d.length2+=b;else if(b>e[0][1].length){var f=b-e[0][1].length;e[0][1]=c.substring(e[0][1].length)+e[0][1];d.start1-=f;d.start2-=f;d.length1+=f;d.length2+=f}d=a[a.length-1];e=d.diffs;0==e.length||0!=e[e.length-1][0]?(e.push([0,
|
||||
c]),d.length1+=b,d.length2+=b):b>e[e.length-1][1].length&&(f=b-e[e.length-1][1].length,e[e.length-1][1]+=c.substring(0,f),d.length1+=f,d.length2+=f);return c};
|
||||
diff_match_patch.prototype.patch_splitMax=function(a){for(var b=this.Match_MaxBits,c=0;c<a.length;c++)if(!(a[c].length1<=b)){var d=a[c];a.splice(c--,1);for(var e=d.start1,f=d.start2,g="";0!==d.diffs.length;){var h=new diff_match_patch.patch_obj,j=!0;h.start1=e-g.length;h.start2=f-g.length;""!==g&&(h.length1=h.length2=g.length,h.diffs.push([0,g]));for(;0!==d.diffs.length&&h.length1<b-this.Patch_Margin;){var g=d.diffs[0][0],i=d.diffs[0][1];1===g?(h.length2+=i.length,f+=i.length,h.diffs.push(d.diffs.shift()),
|
||||
j=!1):-1===g&&1==h.diffs.length&&0==h.diffs[0][0]&&i.length>2*b?(h.length1+=i.length,e+=i.length,j=!1,h.diffs.push([g,i]),d.diffs.shift()):(i=i.substring(0,b-h.length1-this.Patch_Margin),h.length1+=i.length,e+=i.length,0===g?(h.length2+=i.length,f+=i.length):j=!1,h.diffs.push([g,i]),i==d.diffs[0][1]?d.diffs.shift():d.diffs[0][1]=d.diffs[0][1].substring(i.length))}g=this.diff_text2(h.diffs);g=g.substring(g.length-this.Patch_Margin);i=this.diff_text1(d.diffs).substring(0,this.Patch_Margin);""!==i&&
|
||||
(h.length1+=i.length,h.length2+=i.length,0!==h.diffs.length&&0===h.diffs[h.diffs.length-1][0]?h.diffs[h.diffs.length-1][1]+=i:h.diffs.push([0,i]));j||a.splice(++c,0,h)}}};diff_match_patch.prototype.patch_toText=function(a){for(var b=[],c=0;c<a.length;c++)b[c]=a[c];return b.join("")};
|
||||
diff_match_patch.prototype.patch_fromText=function(a){var b=[];if(!a)return b;a=a.split("\n");for(var c=0,d=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;c<a.length;){var e=a[c].match(d);if(!e)throw Error("Invalid patch string: "+a[c]);var f=new diff_match_patch.patch_obj;b.push(f);f.start1=parseInt(e[1],10);""===e[2]?(f.start1--,f.length1=1):"0"==e[2]?f.length1=0:(f.start1--,f.length1=parseInt(e[2],10));f.start2=parseInt(e[3],10);""===e[4]?(f.start2--,f.length2=1):"0"==e[4]?f.length2=0:(f.start2--,f.length2=
|
||||
parseInt(e[4],10));for(c++;c<a.length;){e=a[c].charAt(0);try{var g=decodeURI(a[c].substring(1))}catch(h){throw Error("Illegal escape in patch_fromText: "+g);}if("-"==e)f.diffs.push([-1,g]);else if("+"==e)f.diffs.push([1,g]);else if(" "==e)f.diffs.push([0,g]);else if("@"==e)break;else if(""!==e)throw Error('Invalid patch mode "'+e+'" in: '+g);c++}}return b};diff_match_patch.patch_obj=function(){this.diffs=[];this.start2=this.start1=null;this.length2=this.length1=0};
|
||||
diff_match_patch.patch_obj.prototype.toString=function(){var a,b;a=0===this.length1?this.start1+",0":1==this.length1?this.start1+1:this.start1+1+","+this.length1;b=0===this.length2?this.start2+",0":1==this.length2?this.start2+1:this.start2+1+","+this.length2;a=["@@ -"+a+" +"+b+" @@\n"];var c;for(b=0;b<this.diffs.length;b++){switch(this.diffs[b][0]){case 1:c="+";break;case -1:c="-";break;case 0:c=" "}a[b+1]=c+encodeURI(this.diffs[b][1])+"\n"}return a.join("").replace(/%20/g," ")};
|
||||
this.diff_match_patch=diff_match_patch;this.DIFF_DELETE=-1;this.DIFF_INSERT=1;this.DIFF_EQUAL=0;})()
|
92
plugins/codemirror/codemirror/addon/merge/merge.css
vendored
Normal file
92
plugins/codemirror/codemirror/addon/merge/merge.css
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
.CodeMirror-merge {
|
||||
position: relative;
|
||||
border: 1px solid #ddd;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.CodeMirror-merge, .CodeMirror-merge .CodeMirror {
|
||||
height: 350px;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-2pane .CodeMirror-merge-pane { width: 47%; }
|
||||
.CodeMirror-merge-2pane .CodeMirror-merge-gap { width: 6%; }
|
||||
.CodeMirror-merge-3pane .CodeMirror-merge-pane { width: 31%; }
|
||||
.CodeMirror-merge-3pane .CodeMirror-merge-gap { width: 3.5%; }
|
||||
|
||||
.CodeMirror-merge-pane {
|
||||
display: inline-block;
|
||||
white-space: normal;
|
||||
vertical-align: top;
|
||||
}
|
||||
.CodeMirror-merge-pane-rightmost {
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-gap {
|
||||
z-index: 2;
|
||||
display: inline-block;
|
||||
height: 100%;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
border-left: 1px solid #ddd;
|
||||
border-right: 1px solid #ddd;
|
||||
position: relative;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-scrolllock-wrap {
|
||||
position: absolute;
|
||||
bottom: 0; left: 50%;
|
||||
}
|
||||
.CodeMirror-merge-scrolllock {
|
||||
position: relative;
|
||||
left: -50%;
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-copybuttons-left, .CodeMirror-merge-copybuttons-right {
|
||||
position: absolute;
|
||||
left: 0; top: 0;
|
||||
right: 0; bottom: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-copy {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
color: #44c;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-copybuttons-left .CodeMirror-merge-copy { left: 2px; }
|
||||
.CodeMirror-merge-copybuttons-right .CodeMirror-merge-copy { right: 2px; }
|
||||
|
||||
.CodeMirror-merge-r-inserted, .CodeMirror-merge-l-inserted {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12MwuCXy3+CWyH8GBgYGJgYkAABZbAQ9ELXurwAAAABJRU5ErkJggg==);
|
||||
background-position: bottom left;
|
||||
background-repeat: repeat-x;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-r-deleted, .CodeMirror-merge-l-deleted {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12M4Kyb2/6yY2H8GBgYGJgYkAABURgPz6Ks7wQAAAABJRU5ErkJggg==);
|
||||
background-position: bottom left;
|
||||
background-repeat: repeat-x;
|
||||
}
|
||||
|
||||
.CodeMirror-merge-r-chunk { background: #ffffe0; }
|
||||
.CodeMirror-merge-r-chunk-start { border-top: 1px solid #ee8; }
|
||||
.CodeMirror-merge-r-chunk-end { border-bottom: 1px solid #ee8; }
|
||||
.CodeMirror-merge-r-connect { fill: #ffffe0; stroke: #ee8; stroke-width: 1px; }
|
||||
|
||||
.CodeMirror-merge-l-chunk { background: #eef; }
|
||||
.CodeMirror-merge-l-chunk-start { border-top: 1px solid #88e; }
|
||||
.CodeMirror-merge-l-chunk-end { border-bottom: 1px solid #88e; }
|
||||
.CodeMirror-merge-l-connect { fill: #eef; stroke: #88e; stroke-width: 1px; }
|
||||
|
||||
.CodeMirror-merge-l-chunk.CodeMirror-merge-r-chunk { background: #dfd; }
|
||||
.CodeMirror-merge-l-chunk-start.CodeMirror-merge-r-chunk-start { border-top: 1px solid #4e4; }
|
||||
.CodeMirror-merge-l-chunk-end.CodeMirror-merge-r-chunk-end { border-bottom: 1px solid #4e4; }
|
474
plugins/codemirror/codemirror/addon/merge/merge.js
vendored
Normal file
474
plugins/codemirror/codemirror/addon/merge/merge.js
vendored
Normal file
@@ -0,0 +1,474 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
// declare global: diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
var svgNS = "http://www.w3.org/2000/svg";
|
||||
|
||||
function DiffView(mv, type) {
|
||||
this.mv = mv;
|
||||
this.type = type;
|
||||
this.classes = type == "left"
|
||||
? {chunk: "CodeMirror-merge-l-chunk",
|
||||
start: "CodeMirror-merge-l-chunk-start",
|
||||
end: "CodeMirror-merge-l-chunk-end",
|
||||
insert: "CodeMirror-merge-l-inserted",
|
||||
del: "CodeMirror-merge-l-deleted",
|
||||
connect: "CodeMirror-merge-l-connect"}
|
||||
: {chunk: "CodeMirror-merge-r-chunk",
|
||||
start: "CodeMirror-merge-r-chunk-start",
|
||||
end: "CodeMirror-merge-r-chunk-end",
|
||||
insert: "CodeMirror-merge-r-inserted",
|
||||
del: "CodeMirror-merge-r-deleted",
|
||||
connect: "CodeMirror-merge-r-connect"};
|
||||
}
|
||||
|
||||
DiffView.prototype = {
|
||||
constructor: DiffView,
|
||||
init: function(pane, orig, options) {
|
||||
this.edit = this.mv.edit;
|
||||
this.orig = CodeMirror(pane, copyObj({value: orig, readOnly: true}, copyObj(options)));
|
||||
|
||||
this.diff = getDiff(orig, options.value);
|
||||
this.diffOutOfDate = false;
|
||||
|
||||
this.showDifferences = options.showDifferences !== false;
|
||||
this.forceUpdate = registerUpdate(this);
|
||||
setScrollLock(this, true, false);
|
||||
registerScroll(this);
|
||||
},
|
||||
setShowDifferences: function(val) {
|
||||
val = val !== false;
|
||||
if (val != this.showDifferences) {
|
||||
this.showDifferences = val;
|
||||
this.forceUpdate("full");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function registerUpdate(dv) {
|
||||
var edit = {from: 0, to: 0, marked: []};
|
||||
var orig = {from: 0, to: 0, marked: []};
|
||||
var debounceChange;
|
||||
function update(mode) {
|
||||
if (mode == "full") {
|
||||
if (dv.svg) clear(dv.svg);
|
||||
clear(dv.copyButtons);
|
||||
clearMarks(dv.edit, edit.marked, dv.classes);
|
||||
clearMarks(dv.orig, orig.marked, dv.classes);
|
||||
edit.from = edit.to = orig.from = orig.to = 0;
|
||||
}
|
||||
if (dv.diffOutOfDate) {
|
||||
dv.diff = getDiff(dv.orig.getValue(), dv.edit.getValue());
|
||||
dv.diffOutOfDate = false;
|
||||
CodeMirror.signal(dv.edit, "updateDiff", dv.diff);
|
||||
}
|
||||
if (dv.showDifferences) {
|
||||
updateMarks(dv.edit, dv.diff, edit, DIFF_INSERT, dv.classes);
|
||||
updateMarks(dv.orig, dv.diff, orig, DIFF_DELETE, dv.classes);
|
||||
}
|
||||
drawConnectors(dv);
|
||||
}
|
||||
function set(slow) {
|
||||
clearTimeout(debounceChange);
|
||||
debounceChange = setTimeout(update, slow == true ? 250 : 100);
|
||||
}
|
||||
function change() {
|
||||
if (!dv.diffOutOfDate) {
|
||||
dv.diffOutOfDate = true;
|
||||
edit.from = edit.to = orig.from = orig.to = 0;
|
||||
}
|
||||
set(true);
|
||||
}
|
||||
dv.edit.on("change", change);
|
||||
dv.orig.on("change", change);
|
||||
dv.edit.on("viewportChange", set);
|
||||
dv.orig.on("viewportChange", set);
|
||||
update();
|
||||
return update;
|
||||
}
|
||||
|
||||
function registerScroll(dv) {
|
||||
dv.edit.on("scroll", function() {
|
||||
syncScroll(dv, DIFF_INSERT) && drawConnectors(dv);
|
||||
});
|
||||
dv.orig.on("scroll", function() {
|
||||
syncScroll(dv, DIFF_DELETE) && drawConnectors(dv);
|
||||
});
|
||||
}
|
||||
|
||||
function syncScroll(dv, type) {
|
||||
// Change handler will do a refresh after a timeout when diff is out of date
|
||||
if (dv.diffOutOfDate) return false;
|
||||
if (!dv.lockScroll) return true;
|
||||
var editor, other, now = +new Date;
|
||||
if (type == DIFF_INSERT) { editor = dv.edit; other = dv.orig; }
|
||||
else { editor = dv.orig; other = dv.edit; }
|
||||
// Don't take action if the position of this editor was recently set
|
||||
// (to prevent feedback loops)
|
||||
if (editor.state.scrollSetBy == dv && (editor.state.scrollSetAt || 0) + 50 > now) return false;
|
||||
|
||||
var sInfo = editor.getScrollInfo(), halfScreen = .5 * sInfo.clientHeight, midY = sInfo.top + halfScreen;
|
||||
var mid = editor.lineAtHeight(midY, "local");
|
||||
var around = chunkBoundariesAround(dv.diff, mid, type == DIFF_INSERT);
|
||||
var off = getOffsets(editor, type == DIFF_INSERT ? around.edit : around.orig);
|
||||
var offOther = getOffsets(other, type == DIFF_INSERT ? around.orig : around.edit);
|
||||
var ratio = (midY - off.top) / (off.bot - off.top);
|
||||
var targetPos = (offOther.top - halfScreen) + ratio * (offOther.bot - offOther.top);
|
||||
|
||||
var botDist, mix;
|
||||
// Some careful tweaking to make sure no space is left out of view
|
||||
// when scrolling to top or bottom.
|
||||
if (targetPos > sInfo.top && (mix = sInfo.top / halfScreen) < 1) {
|
||||
targetPos = targetPos * mix + sInfo.top * (1 - mix);
|
||||
} else if ((botDist = sInfo.height - sInfo.clientHeight - sInfo.top) < halfScreen) {
|
||||
var otherInfo = other.getScrollInfo();
|
||||
var botDistOther = otherInfo.height - otherInfo.clientHeight - targetPos;
|
||||
if (botDistOther > botDist && (mix = botDist / halfScreen) < 1)
|
||||
targetPos = targetPos * mix + (otherInfo.height - otherInfo.clientHeight - botDist) * (1 - mix);
|
||||
}
|
||||
|
||||
other.scrollTo(sInfo.left, targetPos);
|
||||
other.state.scrollSetAt = now;
|
||||
other.state.scrollSetBy = dv;
|
||||
return true;
|
||||
}
|
||||
|
||||
function getOffsets(editor, around) {
|
||||
var bot = around.after;
|
||||
if (bot == null) bot = editor.lastLine() + 1;
|
||||
return {top: editor.heightAtLine(around.before || 0, "local"),
|
||||
bot: editor.heightAtLine(bot, "local")};
|
||||
}
|
||||
|
||||
function setScrollLock(dv, val, action) {
|
||||
dv.lockScroll = val;
|
||||
if (val && action != false) syncScroll(dv, DIFF_INSERT) && drawConnectors(dv);
|
||||
dv.lockButton.innerHTML = val ? "\u21db\u21da" : "\u21db \u21da";
|
||||
}
|
||||
|
||||
// Updating the marks for editor content
|
||||
|
||||
function clearMarks(editor, arr, classes) {
|
||||
for (var i = 0; i < arr.length; ++i) {
|
||||
var mark = arr[i];
|
||||
if (mark instanceof CodeMirror.TextMarker) {
|
||||
mark.clear();
|
||||
} else {
|
||||
editor.removeLineClass(mark, "background", classes.chunk);
|
||||
editor.removeLineClass(mark, "background", classes.start);
|
||||
editor.removeLineClass(mark, "background", classes.end);
|
||||
}
|
||||
}
|
||||
arr.length = 0;
|
||||
}
|
||||
|
||||
// FIXME maybe add a margin around viewport to prevent too many updates
|
||||
function updateMarks(editor, diff, state, type, classes) {
|
||||
var vp = editor.getViewport();
|
||||
editor.operation(function() {
|
||||
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
|
||||
clearMarks(editor, state.marked, classes);
|
||||
markChanges(editor, diff, type, state.marked, vp.from, vp.to, classes);
|
||||
state.from = vp.from; state.to = vp.to;
|
||||
} else {
|
||||
if (vp.from < state.from) {
|
||||
markChanges(editor, diff, type, state.marked, vp.from, state.from, classes);
|
||||
state.from = vp.from;
|
||||
}
|
||||
if (vp.to > state.to) {
|
||||
markChanges(editor, diff, type, state.marked, state.to, vp.to, classes);
|
||||
state.to = vp.to;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function markChanges(editor, diff, type, marks, from, to, classes) {
|
||||
var pos = Pos(0, 0);
|
||||
var top = Pos(from, 0), bot = editor.clipPos(Pos(to - 1));
|
||||
var cls = type == DIFF_DELETE ? classes.del : classes.insert;
|
||||
function markChunk(start, end) {
|
||||
var bfrom = Math.max(from, start), bto = Math.min(to, end);
|
||||
for (var i = bfrom; i < bto; ++i) {
|
||||
var line = editor.addLineClass(i, "background", classes.chunk);
|
||||
if (i == start) editor.addLineClass(line, "background", classes.start);
|
||||
if (i == end - 1) editor.addLineClass(line, "background", classes.end);
|
||||
marks.push(line);
|
||||
}
|
||||
// When the chunk is empty, make sure a horizontal line shows up
|
||||
if (start == end && bfrom == end && bto == end) {
|
||||
if (bfrom)
|
||||
marks.push(editor.addLineClass(bfrom - 1, "background", classes.end));
|
||||
else
|
||||
marks.push(editor.addLineClass(bfrom, "background", classes.start));
|
||||
}
|
||||
}
|
||||
|
||||
var chunkStart = 0;
|
||||
for (var i = 0; i < diff.length; ++i) {
|
||||
var part = diff[i], tp = part[0], str = part[1];
|
||||
if (tp == DIFF_EQUAL) {
|
||||
var cleanFrom = pos.line + (startOfLineClean(diff, i) ? 0 : 1);
|
||||
moveOver(pos, str);
|
||||
var cleanTo = pos.line + (endOfLineClean(diff, i) ? 1 : 0);
|
||||
if (cleanTo > cleanFrom) {
|
||||
if (i) markChunk(chunkStart, cleanFrom);
|
||||
chunkStart = cleanTo;
|
||||
}
|
||||
} else {
|
||||
if (tp == type) {
|
||||
var end = moveOver(pos, str, true);
|
||||
var a = posMax(top, pos), b = posMin(bot, end);
|
||||
if (!posEq(a, b))
|
||||
marks.push(editor.markText(a, b, {className: cls}));
|
||||
pos = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chunkStart <= pos.line) markChunk(chunkStart, pos.line + 1);
|
||||
}
|
||||
|
||||
// Updating the gap between editor and original
|
||||
|
||||
function drawConnectors(dv) {
|
||||
if (!dv.showDifferences) return;
|
||||
|
||||
if (dv.svg) {
|
||||
clear(dv.svg);
|
||||
var w = dv.gap.offsetWidth;
|
||||
attrs(dv.svg, "width", w, "height", dv.gap.offsetHeight);
|
||||
}
|
||||
clear(dv.copyButtons);
|
||||
|
||||
var flip = dv.type == "left";
|
||||
var vpEdit = dv.edit.getViewport(), vpOrig = dv.orig.getViewport();
|
||||
var sTopEdit = dv.edit.getScrollInfo().top, sTopOrig = dv.orig.getScrollInfo().top;
|
||||
iterateChunks(dv.diff, function(topOrig, botOrig, topEdit, botEdit) {
|
||||
if (topEdit > vpEdit.to || botEdit < vpEdit.from ||
|
||||
topOrig > vpOrig.to || botOrig < vpOrig.from)
|
||||
return;
|
||||
var topLpx = dv.orig.heightAtLine(topOrig, "local") - sTopOrig, top = topLpx;
|
||||
if (dv.svg) {
|
||||
var topRpx = dv.edit.heightAtLine(topEdit, "local") - sTopEdit;
|
||||
if (flip) { var tmp = topLpx; topLpx = topRpx; topRpx = tmp; }
|
||||
var botLpx = dv.orig.heightAtLine(botOrig, "local") - sTopOrig;
|
||||
var botRpx = dv.edit.heightAtLine(botEdit, "local") - sTopEdit;
|
||||
if (flip) { var tmp = botLpx; botLpx = botRpx; botRpx = tmp; }
|
||||
var curveTop = " C " + w/2 + " " + topRpx + " " + w/2 + " " + topLpx + " " + (w + 2) + " " + topLpx;
|
||||
var curveBot = " C " + w/2 + " " + botLpx + " " + w/2 + " " + botRpx + " -1 " + botRpx;
|
||||
attrs(dv.svg.appendChild(document.createElementNS(svgNS, "path")),
|
||||
"d", "M -1 " + topRpx + curveTop + " L " + (w + 2) + " " + botLpx + curveBot + " z",
|
||||
"class", dv.classes.connect);
|
||||
}
|
||||
var copy = dv.copyButtons.appendChild(elt("div", dv.type == "left" ? "\u21dd" : "\u21dc",
|
||||
"CodeMirror-merge-copy"));
|
||||
copy.title = "Revert chunk";
|
||||
copy.chunk = {topEdit: topEdit, botEdit: botEdit, topOrig: topOrig, botOrig: botOrig};
|
||||
copy.style.top = top + "px";
|
||||
});
|
||||
}
|
||||
|
||||
function copyChunk(dv, chunk) {
|
||||
if (dv.diffOutOfDate) return;
|
||||
dv.edit.replaceRange(dv.orig.getRange(Pos(chunk.topOrig, 0), Pos(chunk.botOrig, 0)),
|
||||
Pos(chunk.topEdit, 0), Pos(chunk.botEdit, 0));
|
||||
}
|
||||
|
||||
// Merge view, containing 0, 1, or 2 diff views.
|
||||
|
||||
var MergeView = CodeMirror.MergeView = function(node, options) {
|
||||
if (!(this instanceof MergeView)) return new MergeView(node, options);
|
||||
|
||||
var origLeft = options.origLeft, origRight = options.origRight == null ? options.orig : options.origRight;
|
||||
var hasLeft = origLeft != null, hasRight = origRight != null;
|
||||
var panes = 1 + (hasLeft ? 1 : 0) + (hasRight ? 1 : 0);
|
||||
var wrap = [], left = this.left = null, right = this.right = null;
|
||||
|
||||
if (hasLeft) {
|
||||
left = this.left = new DiffView(this, "left");
|
||||
var leftPane = elt("div", null, "CodeMirror-merge-pane");
|
||||
wrap.push(leftPane);
|
||||
wrap.push(buildGap(left));
|
||||
}
|
||||
|
||||
var editPane = elt("div", null, "CodeMirror-merge-pane");
|
||||
wrap.push(editPane);
|
||||
|
||||
if (hasRight) {
|
||||
right = this.right = new DiffView(this, "right");
|
||||
wrap.push(buildGap(right));
|
||||
var rightPane = elt("div", null, "CodeMirror-merge-pane");
|
||||
wrap.push(rightPane);
|
||||
}
|
||||
|
||||
(hasRight ? rightPane : editPane).className += " CodeMirror-merge-pane-rightmost";
|
||||
|
||||
wrap.push(elt("div", null, null, "height: 0; clear: both;"));
|
||||
var wrapElt = this.wrap = node.appendChild(elt("div", wrap, "CodeMirror-merge CodeMirror-merge-" + panes + "pane"));
|
||||
this.edit = CodeMirror(editPane, copyObj(options));
|
||||
|
||||
if (left) left.init(leftPane, origLeft, options);
|
||||
if (right) right.init(rightPane, origRight, options);
|
||||
|
||||
var onResize = function() {
|
||||
if (left) drawConnectors(left);
|
||||
if (right) drawConnectors(right);
|
||||
};
|
||||
CodeMirror.on(window, "resize", onResize);
|
||||
var resizeInterval = setInterval(function() {
|
||||
for (var p = wrapElt.parentNode; p && p != document.body; p = p.parentNode) {}
|
||||
if (!p) { clearInterval(resizeInterval); CodeMirror.off(window, "resize", onResize); }
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
function buildGap(dv) {
|
||||
var lock = dv.lockButton = elt("div", null, "CodeMirror-merge-scrolllock");
|
||||
lock.title = "Toggle locked scrolling";
|
||||
var lockWrap = elt("div", [lock], "CodeMirror-merge-scrolllock-wrap");
|
||||
CodeMirror.on(lock, "click", function() { setScrollLock(dv, !dv.lockScroll); });
|
||||
dv.copyButtons = elt("div", null, "CodeMirror-merge-copybuttons-" + dv.type);
|
||||
CodeMirror.on(dv.copyButtons, "click", function(e) {
|
||||
var node = e.target || e.srcElement;
|
||||
if (node.chunk) copyChunk(dv, node.chunk);
|
||||
});
|
||||
var gapElts = [dv.copyButtons, lockWrap];
|
||||
var svg = document.createElementNS && document.createElementNS(svgNS, "svg");
|
||||
if (svg && !svg.createSVGRect) svg = null;
|
||||
dv.svg = svg;
|
||||
if (svg) gapElts.push(svg);
|
||||
|
||||
return dv.gap = elt("div", gapElts, "CodeMirror-merge-gap");
|
||||
}
|
||||
|
||||
MergeView.prototype = {
|
||||
constuctor: MergeView,
|
||||
editor: function() { return this.edit; },
|
||||
rightOriginal: function() { return this.right && this.right.orig; },
|
||||
leftOriginal: function() { return this.left && this.left.orig; },
|
||||
setShowDifferences: function(val) {
|
||||
if (this.right) this.right.setShowDifferences(val);
|
||||
if (this.left) this.left.setShowDifferences(val);
|
||||
}
|
||||
};
|
||||
|
||||
// Operations on diffs
|
||||
|
||||
var dmp = new diff_match_patch();
|
||||
function getDiff(a, b) {
|
||||
var diff = dmp.diff_main(a, b);
|
||||
dmp.diff_cleanupSemantic(diff);
|
||||
// The library sometimes leaves in empty parts, which confuse the algorithm
|
||||
for (var i = 0; i < diff.length; ++i) {
|
||||
var part = diff[i];
|
||||
if (!part[1]) {
|
||||
diff.splice(i--, 1);
|
||||
} else if (i && diff[i - 1][0] == part[0]) {
|
||||
diff.splice(i--, 1);
|
||||
diff[i][1] += part[1];
|
||||
}
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
function iterateChunks(diff, f) {
|
||||
var startEdit = 0, startOrig = 0;
|
||||
var edit = Pos(0, 0), orig = Pos(0, 0);
|
||||
for (var i = 0; i < diff.length; ++i) {
|
||||
var part = diff[i], tp = part[0];
|
||||
if (tp == DIFF_EQUAL) {
|
||||
var startOff = startOfLineClean(diff, i) ? 0 : 1;
|
||||
var cleanFromEdit = edit.line + startOff, cleanFromOrig = orig.line + startOff;
|
||||
moveOver(edit, part[1], null, orig);
|
||||
var endOff = endOfLineClean(diff, i) ? 1 : 0;
|
||||
var cleanToEdit = edit.line + endOff, cleanToOrig = orig.line + endOff;
|
||||
if (cleanToEdit > cleanFromEdit) {
|
||||
if (i) f(startOrig, cleanFromOrig, startEdit, cleanFromEdit);
|
||||
startEdit = cleanToEdit; startOrig = cleanToOrig;
|
||||
}
|
||||
} else {
|
||||
moveOver(tp == DIFF_INSERT ? edit : orig, part[1]);
|
||||
}
|
||||
}
|
||||
if (startEdit <= edit.line || startOrig <= orig.line)
|
||||
f(startOrig, orig.line + 1, startEdit, edit.line + 1);
|
||||
}
|
||||
|
||||
function endOfLineClean(diff, i) {
|
||||
if (i == diff.length - 1) return true;
|
||||
var next = diff[i + 1][1];
|
||||
if (next.length == 1 || next.charCodeAt(0) != 10) return false;
|
||||
if (i == diff.length - 2) return true;
|
||||
next = diff[i + 2][1];
|
||||
return next.length > 1 && next.charCodeAt(0) == 10;
|
||||
}
|
||||
|
||||
function startOfLineClean(diff, i) {
|
||||
if (i == 0) return true;
|
||||
var last = diff[i - 1][1];
|
||||
if (last.charCodeAt(last.length - 1) != 10) return false;
|
||||
if (i == 1) return true;
|
||||
last = diff[i - 2][1];
|
||||
return last.charCodeAt(last.length - 1) == 10;
|
||||
}
|
||||
|
||||
function chunkBoundariesAround(diff, n, nInEdit) {
|
||||
var beforeE, afterE, beforeO, afterO;
|
||||
iterateChunks(diff, function(fromOrig, toOrig, fromEdit, toEdit) {
|
||||
var fromLocal = nInEdit ? fromEdit : fromOrig;
|
||||
var toLocal = nInEdit ? toEdit : toOrig;
|
||||
if (afterE == null) {
|
||||
if (fromLocal > n) { afterE = fromEdit; afterO = fromOrig; }
|
||||
else if (toLocal > n) { afterE = toEdit; afterO = toOrig; }
|
||||
}
|
||||
if (toLocal <= n) { beforeE = toEdit; beforeO = toOrig; }
|
||||
else if (fromLocal <= n) { beforeE = fromEdit; beforeO = fromOrig; }
|
||||
});
|
||||
return {edit: {before: beforeE, after: afterE}, orig: {before: beforeO, after: afterO}};
|
||||
}
|
||||
|
||||
// General utilities
|
||||
|
||||
function elt(tag, content, className, style) {
|
||||
var e = document.createElement(tag);
|
||||
if (className) e.className = className;
|
||||
if (style) e.style.cssText = style;
|
||||
if (typeof content == "string") e.appendChild(document.createTextNode(content));
|
||||
else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
|
||||
return e;
|
||||
}
|
||||
|
||||
function clear(node) {
|
||||
for (var count = node.childNodes.length; count > 0; --count)
|
||||
node.removeChild(node.firstChild);
|
||||
}
|
||||
|
||||
function attrs(elt) {
|
||||
for (var i = 1; i < arguments.length; i += 2)
|
||||
elt.setAttribute(arguments[i], arguments[i+1]);
|
||||
}
|
||||
|
||||
function copyObj(obj, target) {
|
||||
if (!target) target = {};
|
||||
for (var prop in obj) if (obj.hasOwnProperty(prop)) target[prop] = obj[prop];
|
||||
return target;
|
||||
}
|
||||
|
||||
function moveOver(pos, str, copy, other) {
|
||||
var out = copy ? Pos(pos.line, pos.ch) : pos, at = 0;
|
||||
for (;;) {
|
||||
var nl = str.indexOf("\n", at);
|
||||
if (nl == -1) break;
|
||||
++out.line;
|
||||
if (other) ++other.line;
|
||||
at = nl + 1;
|
||||
}
|
||||
out.ch = (at ? 0 : out.ch) + (str.length - at);
|
||||
if (other) other.ch = (at ? 0 : other.ch) + (str.length - at);
|
||||
return out;
|
||||
}
|
||||
|
||||
function posMin(a, b) { return (a.line - b.line || a.ch - b.ch) < 0 ? a : b; }
|
||||
function posMax(a, b) { return (a.line - b.line || a.ch - b.ch) > 0 ? a : b; }
|
||||
function posEq(a, b) { return a.line == b.line && a.ch == b.ch; }
|
||||
})();
|
51
plugins/codemirror/codemirror/addon/mode/loadmode.js
vendored
Normal file
51
plugins/codemirror/codemirror/addon/mode/loadmode.js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
(function() {
|
||||
if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
|
||||
|
||||
var loading = {};
|
||||
function splitCallback(cont, n) {
|
||||
var countDown = n;
|
||||
return function() { if (--countDown == 0) cont(); };
|
||||
}
|
||||
function ensureDeps(mode, cont) {
|
||||
var deps = CodeMirror.modes[mode].dependencies;
|
||||
if (!deps) return cont();
|
||||
var missing = [];
|
||||
for (var i = 0; i < deps.length; ++i) {
|
||||
if (!CodeMirror.modes.hasOwnProperty(deps[i]))
|
||||
missing.push(deps[i]);
|
||||
}
|
||||
if (!missing.length) return cont();
|
||||
var split = splitCallback(cont, missing.length);
|
||||
for (var i = 0; i < missing.length; ++i)
|
||||
CodeMirror.requireMode(missing[i], split);
|
||||
}
|
||||
|
||||
CodeMirror.requireMode = function(mode, cont) {
|
||||
if (typeof mode != "string") mode = mode.name;
|
||||
if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
|
||||
if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
|
||||
|
||||
var script = document.createElement("script");
|
||||
script.src = CodeMirror.modeURL.replace(/%N/g, mode);
|
||||
var others = document.getElementsByTagName("script")[0];
|
||||
others.parentNode.insertBefore(script, others);
|
||||
var list = loading[mode] = [cont];
|
||||
var count = 0, poll = setInterval(function() {
|
||||
if (++count > 100) return clearInterval(poll);
|
||||
if (CodeMirror.modes.hasOwnProperty(mode)) {
|
||||
clearInterval(poll);
|
||||
loading[mode] = null;
|
||||
ensureDeps(mode, function() {
|
||||
for (var i = 0; i < list.length; ++i) list[i]();
|
||||
});
|
||||
}
|
||||
}, 200);
|
||||
};
|
||||
|
||||
CodeMirror.autoLoadMode = function(instance, mode) {
|
||||
if (!CodeMirror.modes.hasOwnProperty(mode))
|
||||
CodeMirror.requireMode(mode, function() {
|
||||
instance.setOption("mode", instance.getOption("mode"));
|
||||
});
|
||||
};
|
||||
}());
|
101
plugins/codemirror/codemirror/addon/mode/multiplex.js
vendored
Normal file
101
plugins/codemirror/codemirror/addon/mode/multiplex.js
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
CodeMirror.multiplexingMode = function(outer /*, others */) {
|
||||
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
|
||||
var others = Array.prototype.slice.call(arguments, 1);
|
||||
var n_others = others.length;
|
||||
|
||||
function indexOf(string, pattern, from) {
|
||||
if (typeof pattern == "string") return string.indexOf(pattern, from);
|
||||
var m = pattern.exec(from ? string.slice(from) : string);
|
||||
return m ? m.index + from : -1;
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
outer: CodeMirror.startState(outer),
|
||||
innerActive: null,
|
||||
inner: null
|
||||
};
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {
|
||||
outer: CodeMirror.copyState(outer, state.outer),
|
||||
innerActive: state.innerActive,
|
||||
inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (!state.innerActive) {
|
||||
var cutOff = Infinity, oldContent = stream.string;
|
||||
for (var i = 0; i < n_others; ++i) {
|
||||
var other = others[i];
|
||||
var found = indexOf(oldContent, other.open, stream.pos);
|
||||
if (found == stream.pos) {
|
||||
stream.match(other.open);
|
||||
state.innerActive = other;
|
||||
state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
|
||||
return other.delimStyle;
|
||||
} else if (found != -1 && found < cutOff) {
|
||||
cutOff = found;
|
||||
}
|
||||
}
|
||||
if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);
|
||||
var outerToken = outer.token(stream, state.outer);
|
||||
if (cutOff != Infinity) stream.string = oldContent;
|
||||
return outerToken;
|
||||
} else {
|
||||
var curInner = state.innerActive, oldContent = stream.string;
|
||||
var found = indexOf(oldContent, curInner.close, stream.pos);
|
||||
if (found == stream.pos) {
|
||||
stream.match(curInner.close);
|
||||
state.innerActive = state.inner = null;
|
||||
return curInner.delimStyle;
|
||||
}
|
||||
if (found > -1) stream.string = oldContent.slice(0, found);
|
||||
var innerToken = curInner.mode.token(stream, state.inner);
|
||||
if (found > -1) stream.string = oldContent;
|
||||
var cur = stream.current(), found = cur.indexOf(curInner.close);
|
||||
if (found > -1) stream.backUp(cur.length - found);
|
||||
|
||||
if (curInner.innerStyle) {
|
||||
if (innerToken) innerToken = innerToken + ' ' + curInner.innerStyle;
|
||||
else innerToken = curInner.innerStyle;
|
||||
}
|
||||
|
||||
return innerToken;
|
||||
}
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var mode = state.innerActive ? state.innerActive.mode : outer;
|
||||
if (!mode.indent) return CodeMirror.Pass;
|
||||
return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
|
||||
},
|
||||
|
||||
blankLine: function(state) {
|
||||
var mode = state.innerActive ? state.innerActive.mode : outer;
|
||||
if (mode.blankLine) {
|
||||
mode.blankLine(state.innerActive ? state.inner : state.outer);
|
||||
}
|
||||
if (!state.innerActive) {
|
||||
for (var i = 0; i < n_others; ++i) {
|
||||
var other = others[i];
|
||||
if (other.open === "\n") {
|
||||
state.innerActive = other;
|
||||
state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
|
||||
}
|
||||
}
|
||||
} else if (state.innerActive.close === "\n") {
|
||||
state.innerActive = state.inner = null;
|
||||
}
|
||||
},
|
||||
|
||||
electricChars: outer.electricChars,
|
||||
|
||||
innerMode: function(state) {
|
||||
return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};
|
||||
}
|
||||
};
|
||||
};
|
30
plugins/codemirror/codemirror/addon/mode/multiplex_test.js
vendored
Normal file
30
plugins/codemirror/codemirror/addon/mode/multiplex_test.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
(function() {
|
||||
CodeMirror.defineMode("markdown_with_stex", function(){
|
||||
var inner = CodeMirror.getMode({}, "stex");
|
||||
var outer = CodeMirror.getMode({}, "markdown");
|
||||
|
||||
var innerOptions = {
|
||||
open: '$',
|
||||
close: '$',
|
||||
mode: inner,
|
||||
delimStyle: 'delim',
|
||||
innerStyle: 'inner'
|
||||
};
|
||||
|
||||
return CodeMirror.multiplexingMode(outer, innerOptions);
|
||||
});
|
||||
|
||||
var mode = CodeMirror.getMode({}, "markdown_with_stex");
|
||||
|
||||
function MT(name) {
|
||||
test.mode(
|
||||
name,
|
||||
mode,
|
||||
Array.prototype.slice.call(arguments, 1),
|
||||
'multiplexing');
|
||||
}
|
||||
|
||||
MT(
|
||||
"stexInsideMarkdown",
|
||||
"[strong **Equation:**] [delim $][inner&tag \\pi][delim $]");
|
||||
})();
|
59
plugins/codemirror/codemirror/addon/mode/overlay.js
vendored
Normal file
59
plugins/codemirror/codemirror/addon/mode/overlay.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// Utility function that allows modes to be combined. The mode given
|
||||
// as the base argument takes care of most of the normal mode
|
||||
// functionality, but a second (typically simple) mode is used, which
|
||||
// can override the style of text. Both modes get to parse all of the
|
||||
// text, but when both assign a non-null style to a piece of code, the
|
||||
// overlay wins, unless the combine argument was true, in which case
|
||||
// the styles are combined.
|
||||
|
||||
// overlayParser is the old, deprecated name
|
||||
CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) {
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
base: CodeMirror.startState(base),
|
||||
overlay: CodeMirror.startState(overlay),
|
||||
basePos: 0, baseCur: null,
|
||||
overlayPos: 0, overlayCur: null
|
||||
};
|
||||
},
|
||||
copyState: function(state) {
|
||||
return {
|
||||
base: CodeMirror.copyState(base, state.base),
|
||||
overlay: CodeMirror.copyState(overlay, state.overlay),
|
||||
basePos: state.basePos, baseCur: null,
|
||||
overlayPos: state.overlayPos, overlayCur: null
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if (stream.start == state.basePos) {
|
||||
state.baseCur = base.token(stream, state.base);
|
||||
state.basePos = stream.pos;
|
||||
}
|
||||
if (stream.start == state.overlayPos) {
|
||||
stream.pos = stream.start;
|
||||
state.overlayCur = overlay.token(stream, state.overlay);
|
||||
state.overlayPos = stream.pos;
|
||||
}
|
||||
stream.pos = Math.min(state.basePos, state.overlayPos);
|
||||
if (stream.eol()) state.basePos = state.overlayPos = 0;
|
||||
|
||||
if (state.overlayCur == null) return state.baseCur;
|
||||
if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
|
||||
else return state.overlayCur;
|
||||
},
|
||||
|
||||
indent: base.indent && function(state, textAfter) {
|
||||
return base.indent(state.base, textAfter);
|
||||
},
|
||||
electricChars: base.electricChars,
|
||||
|
||||
innerMode: function(state) { return {state: state.base, mode: base}; },
|
||||
|
||||
blankLine: function(state) {
|
||||
if (base.blankLine) base.blankLine(state.base);
|
||||
if (overlay.blankLine) overlay.blankLine(state.overlay);
|
||||
}
|
||||
};
|
||||
};
|
29
plugins/codemirror/codemirror/addon/runmode/colorize.js
vendored
Normal file
29
plugins/codemirror/codemirror/addon/runmode/colorize.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
CodeMirror.colorize = (function() {
|
||||
|
||||
var isBlock = /^(p|li|div|h\\d|pre|blockquote|td)$/;
|
||||
|
||||
function textContent(node, out) {
|
||||
if (node.nodeType == 3) return out.push(node.nodeValue);
|
||||
for (var ch = node.firstChild; ch; ch = ch.nextSibling) {
|
||||
textContent(ch, out);
|
||||
if (isBlock.test(node.nodeType)) out.push("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return function(collection, defaultMode) {
|
||||
if (!collection) collection = document.body.getElementsByTagName("pre");
|
||||
|
||||
for (var i = 0; i < collection.length; ++i) {
|
||||
var node = collection[i];
|
||||
var mode = node.getAttribute("data-lang") || defaultMode;
|
||||
if (!mode) continue;
|
||||
|
||||
var text = [];
|
||||
textContent(node, text);
|
||||
node.innerHTML = "";
|
||||
CodeMirror.runMode(text.join(""), mode, node);
|
||||
|
||||
node.className += " cm-s-default";
|
||||
}
|
||||
};
|
||||
})();
|
136
plugins/codemirror/codemirror/addon/runmode/runmode-standalone.js
vendored
Normal file
136
plugins/codemirror/codemirror/addon/runmode/runmode-standalone.js
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
/* Just enough of CodeMirror to run runMode under node.js */
|
||||
|
||||
window.CodeMirror = {};
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
function splitLines(string){ return string.split(/\r?\n|\r/); };
|
||||
|
||||
function StringStream(string) {
|
||||
this.pos = this.start = 0;
|
||||
this.string = string;
|
||||
}
|
||||
StringStream.prototype = {
|
||||
eol: function() {return this.pos >= this.string.length;},
|
||||
sol: function() {return this.pos == 0;},
|
||||
peek: function() {return this.string.charAt(this.pos) || null;},
|
||||
next: function() {
|
||||
if (this.pos < this.string.length)
|
||||
return this.string.charAt(this.pos++);
|
||||
},
|
||||
eat: function(match) {
|
||||
var ch = this.string.charAt(this.pos);
|
||||
if (typeof match == "string") var ok = ch == match;
|
||||
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
||||
if (ok) {++this.pos; return ch;}
|
||||
},
|
||||
eatWhile: function(match) {
|
||||
var start = this.pos;
|
||||
while (this.eat(match)){}
|
||||
return this.pos > start;
|
||||
},
|
||||
eatSpace: function() {
|
||||
var start = this.pos;
|
||||
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
||||
return this.pos > start;
|
||||
},
|
||||
skipToEnd: function() {this.pos = this.string.length;},
|
||||
skipTo: function(ch) {
|
||||
var found = this.string.indexOf(ch, this.pos);
|
||||
if (found > -1) {this.pos = found; return true;}
|
||||
},
|
||||
backUp: function(n) {this.pos -= n;},
|
||||
column: function() {return this.start;},
|
||||
indentation: function() {return 0;},
|
||||
match: function(pattern, consume, caseInsensitive) {
|
||||
if (typeof pattern == "string") {
|
||||
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
|
||||
var substr = this.string.substr(this.pos, pattern.length);
|
||||
if (cased(substr) == cased(pattern)) {
|
||||
if (consume !== false) this.pos += pattern.length;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
var match = this.string.slice(this.pos).match(pattern);
|
||||
if (match && match.index > 0) return null;
|
||||
if (match && consume !== false) this.pos += match[0].length;
|
||||
return match;
|
||||
}
|
||||
},
|
||||
current: function(){return this.string.slice(this.start, this.pos);}
|
||||
};
|
||||
CodeMirror.StringStream = StringStream;
|
||||
|
||||
CodeMirror.startState = function (mode, a1, a2) {
|
||||
return mode.startState ? mode.startState(a1, a2) : true;
|
||||
};
|
||||
|
||||
var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
|
||||
CodeMirror.defineMode = function (name, mode) { modes[name] = mode; };
|
||||
CodeMirror.defineMIME = function (mime, spec) { mimeModes[mime] = spec; };
|
||||
CodeMirror.getMode = function (options, spec) {
|
||||
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
|
||||
spec = mimeModes[spec];
|
||||
if (typeof spec == "string")
|
||||
var mname = spec, config = {};
|
||||
else if (spec != null)
|
||||
var mname = spec.name, config = spec;
|
||||
var mfactory = modes[mname];
|
||||
if (!mfactory) throw new Error("Unknown mode: " + spec);
|
||||
return mfactory(options, config || {});
|
||||
};
|
||||
|
||||
CodeMirror.runMode = function (string, modespec, callback, options) {
|
||||
var mode = CodeMirror.getMode({ indentUnit: 2 }, modespec);
|
||||
|
||||
if (callback.nodeType == 1) {
|
||||
var tabSize = (options && options.tabSize) || 4;
|
||||
var node = callback, col = 0;
|
||||
node.innerHTML = "";
|
||||
callback = function (text, style) {
|
||||
if (text == "\n") {
|
||||
node.appendChild(document.createElement("br"));
|
||||
col = 0;
|
||||
return;
|
||||
}
|
||||
var content = "";
|
||||
// replace tabs
|
||||
for (var pos = 0; ;) {
|
||||
var idx = text.indexOf("\t", pos);
|
||||
if (idx == -1) {
|
||||
content += text.slice(pos);
|
||||
col += text.length - pos;
|
||||
break;
|
||||
} else {
|
||||
col += idx - pos;
|
||||
content += text.slice(pos, idx);
|
||||
var size = tabSize - col % tabSize;
|
||||
col += size;
|
||||
for (var i = 0; i < size; ++i) content += " ";
|
||||
pos = idx + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (style) {
|
||||
var sp = node.appendChild(document.createElement("span"));
|
||||
sp.className = "cm-" + style.replace(/ +/g, " cm-");
|
||||
sp.appendChild(document.createTextNode(content));
|
||||
} else {
|
||||
node.appendChild(document.createTextNode(content));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var lines = splitLines(string), state = CodeMirror.startState(mode);
|
||||
for (var i = 0, e = lines.length; i < e; ++i) {
|
||||
if (i) callback("\n");
|
||||
var stream = new CodeMirror.StringStream(lines[i]);
|
||||
while (!stream.eol()) {
|
||||
var style = mode.token(stream, state);
|
||||
callback(stream.current(), style, i, stream.start, state);
|
||||
stream.start = stream.pos;
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
56
plugins/codemirror/codemirror/addon/runmode/runmode.js
vendored
Normal file
56
plugins/codemirror/codemirror/addon/runmode/runmode.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
CodeMirror.runMode = function(string, modespec, callback, options) {
|
||||
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
|
||||
var ie = /MSIE \d/.test(navigator.userAgent);
|
||||
var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
|
||||
|
||||
if (callback.nodeType == 1) {
|
||||
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
|
||||
var node = callback, col = 0;
|
||||
node.innerHTML = "";
|
||||
callback = function(text, style) {
|
||||
if (text == "\n") {
|
||||
// Emitting LF or CRLF on IE8 or earlier results in an incorrect display.
|
||||
// Emitting a carriage return makes everything ok.
|
||||
node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));
|
||||
col = 0;
|
||||
return;
|
||||
}
|
||||
var content = "";
|
||||
// replace tabs
|
||||
for (var pos = 0;;) {
|
||||
var idx = text.indexOf("\t", pos);
|
||||
if (idx == -1) {
|
||||
content += text.slice(pos);
|
||||
col += text.length - pos;
|
||||
break;
|
||||
} else {
|
||||
col += idx - pos;
|
||||
content += text.slice(pos, idx);
|
||||
var size = tabSize - col % tabSize;
|
||||
col += size;
|
||||
for (var i = 0; i < size; ++i) content += " ";
|
||||
pos = idx + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (style) {
|
||||
var sp = node.appendChild(document.createElement("span"));
|
||||
sp.className = "cm-" + style.replace(/ +/g, " cm-");
|
||||
sp.appendChild(document.createTextNode(content));
|
||||
} else {
|
||||
node.appendChild(document.createTextNode(content));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
|
||||
for (var i = 0, e = lines.length; i < e; ++i) {
|
||||
if (i) callback("\n");
|
||||
var stream = new CodeMirror.StringStream(lines[i]);
|
||||
while (!stream.eol()) {
|
||||
var style = mode.token(stream, state);
|
||||
callback(stream.current(), style, i, stream.start, state);
|
||||
stream.start = stream.pos;
|
||||
}
|
||||
}
|
||||
};
|
103
plugins/codemirror/codemirror/addon/runmode/runmode.node.js
vendored
Normal file
103
plugins/codemirror/codemirror/addon/runmode/runmode.node.js
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
/* Just enough of CodeMirror to run runMode under node.js */
|
||||
|
||||
function splitLines(string){ return string.split(/\r?\n|\r/); };
|
||||
|
||||
function StringStream(string) {
|
||||
this.pos = this.start = 0;
|
||||
this.string = string;
|
||||
}
|
||||
StringStream.prototype = {
|
||||
eol: function() {return this.pos >= this.string.length;},
|
||||
sol: function() {return this.pos == 0;},
|
||||
peek: function() {return this.string.charAt(this.pos) || null;},
|
||||
next: function() {
|
||||
if (this.pos < this.string.length)
|
||||
return this.string.charAt(this.pos++);
|
||||
},
|
||||
eat: function(match) {
|
||||
var ch = this.string.charAt(this.pos);
|
||||
if (typeof match == "string") var ok = ch == match;
|
||||
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
||||
if (ok) {++this.pos; return ch;}
|
||||
},
|
||||
eatWhile: function(match) {
|
||||
var start = this.pos;
|
||||
while (this.eat(match)){}
|
||||
return this.pos > start;
|
||||
},
|
||||
eatSpace: function() {
|
||||
var start = this.pos;
|
||||
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
||||
return this.pos > start;
|
||||
},
|
||||
skipToEnd: function() {this.pos = this.string.length;},
|
||||
skipTo: function(ch) {
|
||||
var found = this.string.indexOf(ch, this.pos);
|
||||
if (found > -1) {this.pos = found; return true;}
|
||||
},
|
||||
backUp: function(n) {this.pos -= n;},
|
||||
column: function() {return this.start;},
|
||||
indentation: function() {return 0;},
|
||||
match: function(pattern, consume, caseInsensitive) {
|
||||
if (typeof pattern == "string") {
|
||||
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
|
||||
var substr = this.string.substr(this.pos, pattern.length);
|
||||
if (cased(substr) == cased(pattern)) {
|
||||
if (consume !== false) this.pos += pattern.length;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
var match = this.string.slice(this.pos).match(pattern);
|
||||
if (match && match.index > 0) return null;
|
||||
if (match && consume !== false) this.pos += match[0].length;
|
||||
return match;
|
||||
}
|
||||
},
|
||||
current: function(){return this.string.slice(this.start, this.pos);}
|
||||
};
|
||||
exports.StringStream = StringStream;
|
||||
|
||||
exports.startState = function(mode, a1, a2) {
|
||||
return mode.startState ? mode.startState(a1, a2) : true;
|
||||
};
|
||||
|
||||
var modes = exports.modes = {}, mimeModes = exports.mimeModes = {};
|
||||
exports.defineMode = function(name, mode) {
|
||||
if (arguments.length > 2) {
|
||||
mode.dependencies = [];
|
||||
for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
|
||||
}
|
||||
modes[name] = mode;
|
||||
};
|
||||
exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; };
|
||||
|
||||
exports.defineMode("null", function() {
|
||||
return {token: function(stream) {stream.skipToEnd();}};
|
||||
});
|
||||
exports.defineMIME("text/plain", "null");
|
||||
|
||||
exports.getMode = function(options, spec) {
|
||||
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
|
||||
spec = mimeModes[spec];
|
||||
if (typeof spec == "string")
|
||||
var mname = spec, config = {};
|
||||
else if (spec != null)
|
||||
var mname = spec.name, config = spec;
|
||||
var mfactory = modes[mname];
|
||||
if (!mfactory) throw new Error("Unknown mode: " + spec);
|
||||
return mfactory(options, config || {});
|
||||
};
|
||||
|
||||
exports.runMode = function(string, modespec, callback) {
|
||||
var mode = exports.getMode({indentUnit: 2}, modespec);
|
||||
var lines = splitLines(string), state = exports.startState(mode);
|
||||
for (var i = 0, e = lines.length; i < e; ++i) {
|
||||
if (i) callback("\n");
|
||||
var stream = new exports.StringStream(lines[i]);
|
||||
while (!stream.eol()) {
|
||||
var style = mode.token(stream, state);
|
||||
callback(stream.current(), style, i, stream.start, state);
|
||||
stream.start = stream.pos;
|
||||
}
|
||||
}
|
||||
};
|
34
plugins/codemirror/codemirror/addon/scroll/scrollpastend.js
vendored
Normal file
34
plugins/codemirror/codemirror/addon/scroll/scrollpastend.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init) {
|
||||
cm.off("change", onChange);
|
||||
cm.display.lineSpace.parentNode.style.paddingBottom = "";
|
||||
cm.state.scrollPastEndPadding = null;
|
||||
}
|
||||
if (val) {
|
||||
cm.on("change", onChange);
|
||||
updateBottomMargin(cm);
|
||||
}
|
||||
});
|
||||
|
||||
function onChange(cm, change) {
|
||||
if (CodeMirror.changeEnd(change).line == cm.lastLine())
|
||||
updateBottomMargin(cm);
|
||||
}
|
||||
|
||||
function updateBottomMargin(cm) {
|
||||
var padding = "";
|
||||
if (cm.lineCount() > 1) {
|
||||
var totalH = cm.display.scroller.clientHeight - 30,
|
||||
lastLineH = cm.getLineHandle(cm.lastLine()).height;
|
||||
padding = (totalH - lastLineH) + "px";
|
||||
}
|
||||
if (cm.state.scrollPastEndPadding != padding) {
|
||||
cm.state.scrollPastEndPadding = padding;
|
||||
cm.display.lineSpace.parentNode.style.paddingBottom = padding;
|
||||
cm.setSize();
|
||||
}
|
||||
}
|
||||
})();
|
91
plugins/codemirror/codemirror/addon/search/match-highlighter.js
vendored
Normal file
91
plugins/codemirror/codemirror/addon/search/match-highlighter.js
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
// Highlighting text that matches the selection
|
||||
//
|
||||
// Defines an option highlightSelectionMatches, which, when enabled,
|
||||
// will style strings that match the selection throughout the
|
||||
// document.
|
||||
//
|
||||
// The option can be set to true to simply enable it, or to a
|
||||
// {minChars, style, showToken} object to explicitly configure it.
|
||||
// minChars is the minimum amount of characters that should be
|
||||
// selected for the behavior to occur, and style is the token style to
|
||||
// apply to the matches. This will be prefixed by "cm-" to create an
|
||||
// actual CSS class name. showToken, when enabled, will cause the
|
||||
// current token to be highlighted when nothing is selected.
|
||||
|
||||
(function() {
|
||||
var DEFAULT_MIN_CHARS = 2;
|
||||
var DEFAULT_TOKEN_STYLE = "matchhighlight";
|
||||
var DEFAULT_DELAY = 100;
|
||||
|
||||
function State(options) {
|
||||
if (typeof options == "object") {
|
||||
this.minChars = options.minChars;
|
||||
this.style = options.style;
|
||||
this.showToken = options.showToken;
|
||||
this.delay = options.delay;
|
||||
}
|
||||
if (this.style == null) this.style = DEFAULT_TOKEN_STYLE;
|
||||
if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS;
|
||||
if (this.delay == null) this.delay = DEFAULT_DELAY;
|
||||
this.overlay = this.timeout = null;
|
||||
}
|
||||
|
||||
CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) {
|
||||
if (old && old != CodeMirror.Init) {
|
||||
var over = cm.state.matchHighlighter.overlay;
|
||||
if (over) cm.removeOverlay(over);
|
||||
clearTimeout(cm.state.matchHighlighter.timeout);
|
||||
cm.state.matchHighlighter = null;
|
||||
cm.off("cursorActivity", cursorActivity);
|
||||
}
|
||||
if (val) {
|
||||
cm.state.matchHighlighter = new State(val);
|
||||
highlightMatches(cm);
|
||||
cm.on("cursorActivity", cursorActivity);
|
||||
}
|
||||
});
|
||||
|
||||
function cursorActivity(cm) {
|
||||
var state = cm.state.matchHighlighter;
|
||||
clearTimeout(state.timeout);
|
||||
state.timeout = setTimeout(function() {highlightMatches(cm);}, state.delay);
|
||||
}
|
||||
|
||||
function highlightMatches(cm) {
|
||||
cm.operation(function() {
|
||||
var state = cm.state.matchHighlighter;
|
||||
if (state.overlay) {
|
||||
cm.removeOverlay(state.overlay);
|
||||
state.overlay = null;
|
||||
}
|
||||
if (!cm.somethingSelected() && state.showToken) {
|
||||
var re = state.showToken === true ? /[\w$]/ : state.showToken;
|
||||
var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;
|
||||
while (start && re.test(line.charAt(start - 1))) --start;
|
||||
while (end < line.length && re.test(line.charAt(end))) ++end;
|
||||
if (start < end)
|
||||
cm.addOverlay(state.overlay = makeOverlay(line.slice(start, end), re, state.style));
|
||||
return;
|
||||
}
|
||||
if (cm.getCursor("head").line != cm.getCursor("anchor").line) return;
|
||||
var selection = cm.getSelection().replace(/^\s+|\s+$/g, "");
|
||||
if (selection.length >= state.minChars)
|
||||
cm.addOverlay(state.overlay = makeOverlay(selection, false, state.style));
|
||||
});
|
||||
}
|
||||
|
||||
function boundariesAround(stream, re) {
|
||||
return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) &&
|
||||
(stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos)));
|
||||
}
|
||||
|
||||
function makeOverlay(query, hasBoundary, style) {
|
||||
return {token: function(stream) {
|
||||
if (stream.match(query) &&
|
||||
(!hasBoundary || boundariesAround(stream, hasBoundary)))
|
||||
return style;
|
||||
stream.next();
|
||||
stream.skipTo(query.charAt(0)) || stream.skipToEnd();
|
||||
}};
|
||||
}
|
||||
})();
|
133
plugins/codemirror/codemirror/addon/search/search.js
vendored
Normal file
133
plugins/codemirror/codemirror/addon/search/search.js
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Define search commands. Depends on dialog.js or another
|
||||
// implementation of the openDialog method.
|
||||
|
||||
// Replace works a little oddly -- it will do the replace on the next
|
||||
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
|
||||
// replace by making sure the match is no longer selected when hitting
|
||||
// Ctrl-G.
|
||||
|
||||
(function() {
|
||||
function searchOverlay(query) {
|
||||
if (typeof query == "string") return {token: function(stream) {
|
||||
if (stream.match(query)) return "searching";
|
||||
stream.next();
|
||||
stream.skipTo(query.charAt(0)) || stream.skipToEnd();
|
||||
}};
|
||||
return {token: function(stream) {
|
||||
if (stream.match(query)) return "searching";
|
||||
while (!stream.eol()) {
|
||||
stream.next();
|
||||
if (stream.match(query, false)) break;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
function SearchState() {
|
||||
this.posFrom = this.posTo = this.query = null;
|
||||
this.overlay = null;
|
||||
}
|
||||
function getSearchState(cm) {
|
||||
return cm.state.search || (cm.state.search = new SearchState());
|
||||
}
|
||||
function getSearchCursor(cm, query, pos) {
|
||||
// Heuristic: if the query string is all lowercase, do a case insensitive search.
|
||||
return cm.getSearchCursor(query, pos, typeof query == "string" && query == query.toLowerCase());
|
||||
}
|
||||
function dialog(cm, text, shortText, f) {
|
||||
if (cm.openDialog) cm.openDialog(text, f);
|
||||
else f(prompt(shortText, ""));
|
||||
}
|
||||
function confirmDialog(cm, text, shortText, fs) {
|
||||
if (cm.openConfirm) cm.openConfirm(text, fs);
|
||||
else if (confirm(shortText)) fs[0]();
|
||||
}
|
||||
function parseQuery(query) {
|
||||
var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
|
||||
return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i") : query;
|
||||
}
|
||||
var queryDialog =
|
||||
'Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
|
||||
function doSearch(cm, rev) {
|
||||
var state = getSearchState(cm);
|
||||
if (state.query) return findNext(cm, rev);
|
||||
dialog(cm, queryDialog, "Search for:", function(query) {
|
||||
cm.operation(function() {
|
||||
if (!query || state.query) return;
|
||||
state.query = parseQuery(query);
|
||||
cm.removeOverlay(state.overlay);
|
||||
state.overlay = searchOverlay(state.query);
|
||||
cm.addOverlay(state.overlay);
|
||||
state.posFrom = state.posTo = cm.getCursor();
|
||||
findNext(cm, rev);
|
||||
});
|
||||
});
|
||||
}
|
||||
function findNext(cm, rev) {cm.operation(function() {
|
||||
var state = getSearchState(cm);
|
||||
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
|
||||
if (!cursor.find(rev)) {
|
||||
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
|
||||
if (!cursor.find(rev)) return;
|
||||
}
|
||||
cm.setSelection(cursor.from(), cursor.to());
|
||||
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
|
||||
state.posFrom = cursor.from(); state.posTo = cursor.to();
|
||||
});}
|
||||
function clearSearch(cm) {cm.operation(function() {
|
||||
var state = getSearchState(cm);
|
||||
if (!state.query) return;
|
||||
state.query = null;
|
||||
cm.removeOverlay(state.overlay);
|
||||
});}
|
||||
|
||||
var replaceQueryDialog =
|
||||
'Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
|
||||
var replacementQueryDialog = 'With: <input type="text" style="width: 10em"/>';
|
||||
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
|
||||
function replace(cm, all) {
|
||||
dialog(cm, replaceQueryDialog, "Replace:", function(query) {
|
||||
if (!query) return;
|
||||
query = parseQuery(query);
|
||||
dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
|
||||
if (all) {
|
||||
cm.operation(function() {
|
||||
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
|
||||
if (typeof query != "string") {
|
||||
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
|
||||
cursor.replace(text.replace(/\$(\d)/, function(_, i) {return match[i];}));
|
||||
} else cursor.replace(text);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
clearSearch(cm);
|
||||
var cursor = getSearchCursor(cm, query, cm.getCursor());
|
||||
var advance = function() {
|
||||
var start = cursor.from(), match;
|
||||
if (!(match = cursor.findNext())) {
|
||||
cursor = getSearchCursor(cm, query);
|
||||
if (!(match = cursor.findNext()) ||
|
||||
(start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
|
||||
}
|
||||
cm.setSelection(cursor.from(), cursor.to());
|
||||
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
|
||||
confirmDialog(cm, doReplaceConfirm, "Replace?",
|
||||
[function() {doReplace(match);}, advance]);
|
||||
};
|
||||
var doReplace = function(match) {
|
||||
cursor.replace(typeof query == "string" ? text :
|
||||
text.replace(/\$(\d)/, function(_, i) {return match[i];}));
|
||||
advance();
|
||||
};
|
||||
advance();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
|
||||
CodeMirror.commands.findNext = doSearch;
|
||||
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
|
||||
CodeMirror.commands.clearSearch = clearSearch;
|
||||
CodeMirror.commands.replace = replace;
|
||||
CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
|
||||
})();
|
143
plugins/codemirror/codemirror/addon/search/searchcursor.js
vendored
Normal file
143
plugins/codemirror/codemirror/addon/search/searchcursor.js
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
(function(){
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function SearchCursor(doc, query, pos, caseFold) {
|
||||
this.atOccurrence = false; this.doc = doc;
|
||||
if (caseFold == null && typeof query == "string") caseFold = false;
|
||||
|
||||
pos = pos ? doc.clipPos(pos) : Pos(0, 0);
|
||||
this.pos = {from: pos, to: pos};
|
||||
|
||||
// The matches method is filled in based on the type of query.
|
||||
// It takes a position and a direction, and returns an object
|
||||
// describing the next occurrence of the query, or null if no
|
||||
// more matches were found.
|
||||
if (typeof query != "string") { // Regexp match
|
||||
if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
|
||||
this.matches = function(reverse, pos) {
|
||||
if (reverse) {
|
||||
query.lastIndex = 0;
|
||||
var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
|
||||
for (;;) {
|
||||
query.lastIndex = cutOff;
|
||||
var newMatch = query.exec(line);
|
||||
if (!newMatch) break;
|
||||
match = newMatch;
|
||||
start = match.index;
|
||||
cutOff = match.index + (match[0].length || 1);
|
||||
if (cutOff == line.length) break;
|
||||
}
|
||||
var matchLen = (match && match[0].length) || 0;
|
||||
if (!matchLen) {
|
||||
if (start == 0 && line.length == 0) {match = undefined;}
|
||||
else if (start != doc.getLine(pos.line).length) {
|
||||
matchLen++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
query.lastIndex = pos.ch;
|
||||
var line = doc.getLine(pos.line), match = query.exec(line);
|
||||
var matchLen = (match && match[0].length) || 0;
|
||||
var start = match && match.index;
|
||||
if (start + matchLen != line.length && !matchLen) matchLen = 1;
|
||||
}
|
||||
if (match && matchLen)
|
||||
return {from: Pos(pos.line, start),
|
||||
to: Pos(pos.line, start + matchLen),
|
||||
match: match};
|
||||
};
|
||||
} else { // String query
|
||||
if (caseFold) query = query.toLowerCase();
|
||||
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
|
||||
var target = query.split("\n");
|
||||
// Different methods for single-line and multi-line queries
|
||||
if (target.length == 1) {
|
||||
if (!query.length) {
|
||||
// Empty string would match anything and never progress, so
|
||||
// we define it to match nothing instead.
|
||||
this.matches = function() {};
|
||||
} else {
|
||||
this.matches = function(reverse, pos) {
|
||||
var line = fold(doc.getLine(pos.line)), len = query.length, match;
|
||||
if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
|
||||
: (match = line.indexOf(query, pos.ch)) != -1)
|
||||
return {from: Pos(pos.line, match),
|
||||
to: Pos(pos.line, match + len)};
|
||||
};
|
||||
}
|
||||
} else {
|
||||
this.matches = function(reverse, pos) {
|
||||
var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(doc.getLine(ln));
|
||||
var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
|
||||
if (reverse ? offsetA > pos.ch || offsetA != match.length
|
||||
: offsetA < pos.ch || offsetA != line.length - match.length)
|
||||
return;
|
||||
for (;;) {
|
||||
if (reverse ? !ln : ln == doc.lineCount() - 1) return;
|
||||
line = fold(doc.getLine(ln += reverse ? -1 : 1));
|
||||
match = target[reverse ? --idx : ++idx];
|
||||
if (idx > 0 && idx < target.length - 1) {
|
||||
if (line != match) return;
|
||||
else continue;
|
||||
}
|
||||
var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
|
||||
if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
|
||||
return;
|
||||
var start = Pos(pos.line, offsetA), end = Pos(ln, offsetB);
|
||||
return {from: reverse ? end : start, to: reverse ? start : end};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SearchCursor.prototype = {
|
||||
findNext: function() {return this.find(false);},
|
||||
findPrevious: function() {return this.find(true);},
|
||||
|
||||
find: function(reverse) {
|
||||
var self = this, pos = this.doc.clipPos(reverse ? this.pos.from : this.pos.to);
|
||||
function savePosAndFail(line) {
|
||||
var pos = Pos(line, 0);
|
||||
self.pos = {from: pos, to: pos};
|
||||
self.atOccurrence = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (this.pos = this.matches(reverse, pos)) {
|
||||
if (!this.pos.from || !this.pos.to) { console.log(this.matches, this.pos); }
|
||||
this.atOccurrence = true;
|
||||
return this.pos.match || true;
|
||||
}
|
||||
if (reverse) {
|
||||
if (!pos.line) return savePosAndFail(0);
|
||||
pos = Pos(pos.line-1, this.doc.getLine(pos.line-1).length);
|
||||
}
|
||||
else {
|
||||
var maxLine = this.doc.lineCount();
|
||||
if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
|
||||
pos = Pos(pos.line + 1, 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
from: function() {if (this.atOccurrence) return this.pos.from;},
|
||||
to: function() {if (this.atOccurrence) return this.pos.to;},
|
||||
|
||||
replace: function(newText) {
|
||||
if (!this.atOccurrence) return;
|
||||
var lines = CodeMirror.splitLines(newText);
|
||||
this.doc.replaceRange(lines, this.pos.from, this.pos.to);
|
||||
this.pos.to = Pos(this.pos.from.line + lines.length - 1,
|
||||
lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
|
||||
return new SearchCursor(this.doc, query, pos, caseFold);
|
||||
});
|
||||
CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
|
||||
return new SearchCursor(this, query, pos, caseFold);
|
||||
});
|
||||
})();
|
39
plugins/codemirror/codemirror/addon/selection/active-line.js
vendored
Normal file
39
plugins/codemirror/codemirror/addon/selection/active-line.js
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// Because sometimes you need to style the cursor's line.
|
||||
//
|
||||
// Adds an option 'styleActiveLine' which, when enabled, gives the
|
||||
// active line's wrapping <div> the CSS class "CodeMirror-activeline",
|
||||
// and gives its background <div> the class "CodeMirror-activeline-background".
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
var WRAP_CLASS = "CodeMirror-activeline";
|
||||
var BACK_CLASS = "CodeMirror-activeline-background";
|
||||
|
||||
CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
|
||||
var prev = old && old != CodeMirror.Init;
|
||||
if (val && !prev) {
|
||||
updateActiveLine(cm);
|
||||
cm.on("cursorActivity", updateActiveLine);
|
||||
} else if (!val && prev) {
|
||||
cm.off("cursorActivity", updateActiveLine);
|
||||
clearActiveLine(cm);
|
||||
delete cm.state.activeLine;
|
||||
}
|
||||
});
|
||||
|
||||
function clearActiveLine(cm) {
|
||||
if ("activeLine" in cm.state) {
|
||||
cm.removeLineClass(cm.state.activeLine, "wrap", WRAP_CLASS);
|
||||
cm.removeLineClass(cm.state.activeLine, "background", BACK_CLASS);
|
||||
}
|
||||
}
|
||||
|
||||
function updateActiveLine(cm) {
|
||||
var line = cm.getLineHandleVisualStart(cm.getCursor().line);
|
||||
if (cm.state.activeLine == line) return;
|
||||
clearActiveLine(cm);
|
||||
cm.addLineClass(line, "wrap", WRAP_CLASS);
|
||||
cm.addLineClass(line, "background", BACK_CLASS);
|
||||
cm.state.activeLine = line;
|
||||
}
|
||||
})();
|
108
plugins/codemirror/codemirror/addon/selection/mark-selection.js
vendored
Normal file
108
plugins/codemirror/codemirror/addon/selection/mark-selection.js
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
// Because sometimes you need to mark the selected *text*.
|
||||
//
|
||||
// Adds an option 'styleSelectedText' which, when enabled, gives
|
||||
// selected text the CSS class given as option value, or
|
||||
// "CodeMirror-selectedtext" when the value is not a string.
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
|
||||
var prev = old && old != CodeMirror.Init;
|
||||
if (val && !prev) {
|
||||
cm.state.markedSelection = [];
|
||||
cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext";
|
||||
reset(cm);
|
||||
cm.on("cursorActivity", onCursorActivity);
|
||||
cm.on("change", onChange);
|
||||
} else if (!val && prev) {
|
||||
cm.off("cursorActivity", onCursorActivity);
|
||||
cm.off("change", onChange);
|
||||
clear(cm);
|
||||
cm.state.markedSelection = cm.state.markedSelectionStyle = null;
|
||||
}
|
||||
});
|
||||
|
||||
function onCursorActivity(cm) {
|
||||
cm.operation(function() { update(cm); });
|
||||
}
|
||||
|
||||
function onChange(cm) {
|
||||
if (cm.state.markedSelection.length)
|
||||
cm.operation(function() { clear(cm); });
|
||||
}
|
||||
|
||||
var CHUNK_SIZE = 8;
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function cmp(pos1, pos2) {
|
||||
return pos1.line - pos2.line || pos1.ch - pos2.ch;
|
||||
}
|
||||
|
||||
function coverRange(cm, from, to, addAt) {
|
||||
if (cmp(from, to) == 0) return;
|
||||
var array = cm.state.markedSelection;
|
||||
var cls = cm.state.markedSelectionStyle;
|
||||
for (var line = from.line;;) {
|
||||
var start = line == from.line ? from : Pos(line, 0);
|
||||
var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line;
|
||||
var end = atEnd ? to : Pos(endLine, 0);
|
||||
var mark = cm.markText(start, end, {className: cls});
|
||||
if (addAt == null) array.push(mark);
|
||||
else array.splice(addAt++, 0, mark);
|
||||
if (atEnd) break;
|
||||
line = endLine;
|
||||
}
|
||||
}
|
||||
|
||||
function clear(cm) {
|
||||
var array = cm.state.markedSelection;
|
||||
for (var i = 0; i < array.length; ++i) array[i].clear();
|
||||
array.length = 0;
|
||||
}
|
||||
|
||||
function reset(cm) {
|
||||
clear(cm);
|
||||
var from = cm.getCursor("start"), to = cm.getCursor("end");
|
||||
coverRange(cm, from, to);
|
||||
}
|
||||
|
||||
function update(cm) {
|
||||
var from = cm.getCursor("start"), to = cm.getCursor("end");
|
||||
if (cmp(from, to) == 0) return clear(cm);
|
||||
|
||||
var array = cm.state.markedSelection;
|
||||
if (!array.length) return coverRange(cm, from, to);
|
||||
|
||||
var coverStart = array[0].find(), coverEnd = array[array.length - 1].find();
|
||||
if (!coverStart || !coverEnd || to.line - from.line < CHUNK_SIZE ||
|
||||
cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0)
|
||||
return reset(cm);
|
||||
|
||||
while (cmp(from, coverStart.from) > 0) {
|
||||
array.shift().clear();
|
||||
coverStart = array[0].find();
|
||||
}
|
||||
if (cmp(from, coverStart.from) < 0) {
|
||||
if (coverStart.to.line - from.line < CHUNK_SIZE) {
|
||||
array.shift().clear();
|
||||
coverRange(cm, from, coverStart.to, 0);
|
||||
} else {
|
||||
coverRange(cm, from, coverStart.from, 0);
|
||||
}
|
||||
}
|
||||
|
||||
while (cmp(to, coverEnd.to) < 0) {
|
||||
array.pop().clear();
|
||||
coverEnd = array[array.length - 1].find();
|
||||
}
|
||||
if (cmp(to, coverEnd.to) > 0) {
|
||||
if (to.line - coverEnd.from.line < CHUNK_SIZE) {
|
||||
array.pop().clear();
|
||||
coverRange(cm, coverEnd.from, to);
|
||||
} else {
|
||||
coverRange(cm, coverEnd.to, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
85
plugins/codemirror/codemirror/addon/tern/tern.css
vendored
Normal file
85
plugins/codemirror/codemirror/addon/tern/tern.css
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
.CodeMirror-Tern-completion {
|
||||
padding-left: 22px;
|
||||
position: relative;
|
||||
}
|
||||
.CodeMirror-Tern-completion:before {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
bottom: 2px;
|
||||
border-radius: 50%;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
height: 15px;
|
||||
width: 15px;
|
||||
line-height: 16px;
|
||||
text-align: center;
|
||||
color: white;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.CodeMirror-Tern-completion-unknown:before {
|
||||
content: "?";
|
||||
background: #4bb;
|
||||
}
|
||||
.CodeMirror-Tern-completion-object:before {
|
||||
content: "O";
|
||||
background: #77c;
|
||||
}
|
||||
.CodeMirror-Tern-completion-fn:before {
|
||||
content: "F";
|
||||
background: #7c7;
|
||||
}
|
||||
.CodeMirror-Tern-completion-array:before {
|
||||
content: "A";
|
||||
background: #c66;
|
||||
}
|
||||
.CodeMirror-Tern-completion-number:before {
|
||||
content: "1";
|
||||
background: #999;
|
||||
}
|
||||
.CodeMirror-Tern-completion-string:before {
|
||||
content: "S";
|
||||
background: #999;
|
||||
}
|
||||
.CodeMirror-Tern-completion-bool:before {
|
||||
content: "B";
|
||||
background: #999;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-completion-guess {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-tooltip {
|
||||
border: 1px solid silver;
|
||||
border-radius: 3px;
|
||||
color: #444;
|
||||
padding: 2px 5px;
|
||||
font-size: 90%;
|
||||
font-family: monospace;
|
||||
background-color: white;
|
||||
white-space: pre-wrap;
|
||||
|
||||
max-width: 40em;
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
|
||||
transition: opacity 1s;
|
||||
-moz-transition: opacity 1s;
|
||||
-webkit-transition: opacity 1s;
|
||||
-o-transition: opacity 1s;
|
||||
-ms-transition: opacity 1s;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-hint-doc {
|
||||
max-width: 25em;
|
||||
}
|
||||
|
||||
.CodeMirror-Tern-fname { color: black; }
|
||||
.CodeMirror-Tern-farg { color: #70a; }
|
||||
.CodeMirror-Tern-farg-current { text-decoration: underline; }
|
||||
.CodeMirror-Tern-type { color: #07c; }
|
||||
.CodeMirror-Tern-fhint-guess { opacity: .7; }
|
632
plugins/codemirror/codemirror/addon/tern/tern.js
vendored
Normal file
632
plugins/codemirror/codemirror/addon/tern/tern.js
vendored
Normal file
@@ -0,0 +1,632 @@
|
||||
// Glue code between CodeMirror and Tern.
|
||||
//
|
||||
// Create a CodeMirror.TernServer to wrap an actual Tern server,
|
||||
// register open documents (CodeMirror.Doc instances) with it, and
|
||||
// call its methods to activate the assisting functions that Tern
|
||||
// provides.
|
||||
//
|
||||
// Options supported (all optional):
|
||||
// * defs: An array of JSON definition data structures.
|
||||
// * plugins: An object mapping plugin names to configuration
|
||||
// options.
|
||||
// * getFile: A function(name, c) that can be used to access files in
|
||||
// the project that haven't been loaded yet. Simply do c(null) to
|
||||
// indicate that a file is not available.
|
||||
// * fileFilter: A function(value, docName, doc) that will be applied
|
||||
// to documents before passing them on to Tern.
|
||||
// * switchToDoc: A function(name) that should, when providing a
|
||||
// multi-file view, switch the view or focus to the named file.
|
||||
// * showError: A function(editor, message) that can be used to
|
||||
// override the way errors are displayed.
|
||||
// * completionTip: Customize the content in tooltips for completions.
|
||||
// Is passed a single argument—the completion's data as returned by
|
||||
// Tern—and may return a string, DOM node, or null to indicate that
|
||||
// no tip should be shown. By default the docstring is shown.
|
||||
// * typeTip: Like completionTip, but for the tooltips shown for type
|
||||
// queries.
|
||||
// * responseFilter: A function(doc, query, request, error, data) that
|
||||
// will be applied to the Tern responses before treating them
|
||||
//
|
||||
//
|
||||
// It is possible to run the Tern server in a web worker by specifying
|
||||
// these additional options:
|
||||
// * useWorker: Set to true to enable web worker mode. You'll probably
|
||||
// want to feature detect the actual value you use here, for example
|
||||
// !!window.Worker.
|
||||
// * workerScript: The main script of the worker. Point this to
|
||||
// wherever you are hosting worker.js from this directory.
|
||||
// * workerDeps: An array of paths pointing (relative to workerScript)
|
||||
// to the Acorn and Tern libraries and any Tern plugins you want to
|
||||
// load. Or, if you minified those into a single script and included
|
||||
// them in the workerScript, simply leave this undefined.
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
// declare global: tern
|
||||
|
||||
CodeMirror.TernServer = function(options) {
|
||||
var self = this;
|
||||
this.options = options || {};
|
||||
var plugins = this.options.plugins || (this.options.plugins = {});
|
||||
if (!plugins.doc_comment) plugins.doc_comment = true;
|
||||
if (this.options.useWorker) {
|
||||
this.server = new WorkerServer(this);
|
||||
} else {
|
||||
this.server = new tern.Server({
|
||||
getFile: function(name, c) { return getFile(self, name, c); },
|
||||
async: true,
|
||||
defs: this.options.defs || [],
|
||||
plugins: plugins
|
||||
});
|
||||
}
|
||||
this.docs = Object.create(null);
|
||||
this.trackChange = function(doc, change) { trackChange(self, doc, change); };
|
||||
|
||||
this.cachedArgHints = null;
|
||||
this.activeArgHints = null;
|
||||
this.jumpStack = [];
|
||||
};
|
||||
|
||||
CodeMirror.TernServer.prototype = {
|
||||
addDoc: function(name, doc) {
|
||||
var data = {doc: doc, name: name, changed: null};
|
||||
this.server.addFile(name, docValue(this, data));
|
||||
CodeMirror.on(doc, "change", this.trackChange);
|
||||
return this.docs[name] = data;
|
||||
},
|
||||
|
||||
delDoc: function(name) {
|
||||
var found = this.docs[name];
|
||||
if (!found) return;
|
||||
CodeMirror.off(found.doc, "change", this.trackChange);
|
||||
delete this.docs[name];
|
||||
this.server.delFile(name);
|
||||
},
|
||||
|
||||
hideDoc: function(name) {
|
||||
closeArgHints(this);
|
||||
var found = this.docs[name];
|
||||
if (found && found.changed) sendDoc(this, found);
|
||||
},
|
||||
|
||||
complete: function(cm) {
|
||||
var self = this;
|
||||
CodeMirror.showHint(cm, function(cm, c) { return hint(self, cm, c); }, {async: true});
|
||||
},
|
||||
|
||||
getHint: function(cm, c) { return hint(this, cm, c); },
|
||||
|
||||
showType: function(cm, pos) { showType(this, cm, pos); },
|
||||
|
||||
updateArgHints: function(cm) { updateArgHints(this, cm); },
|
||||
|
||||
jumpToDef: function(cm) { jumpToDef(this, cm); },
|
||||
|
||||
jumpBack: function(cm) { jumpBack(this, cm); },
|
||||
|
||||
rename: function(cm) { rename(this, cm); },
|
||||
|
||||
request: function (cm, query, c, pos) {
|
||||
var self = this;
|
||||
var doc = findDoc(this, cm.getDoc());
|
||||
var request = buildRequest(this, doc, query, pos);
|
||||
|
||||
this.server.request(request, function (error, data) {
|
||||
if (!error && self.options.responseFilter)
|
||||
data = self.options.responseFilter(doc, query, request, error, data);
|
||||
c(error, data);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
var cls = "CodeMirror-Tern-";
|
||||
var bigDoc = 250;
|
||||
|
||||
function getFile(ts, name, c) {
|
||||
var buf = ts.docs[name];
|
||||
if (buf)
|
||||
c(docValue(ts, buf));
|
||||
else if (ts.options.getFile)
|
||||
ts.options.getFile(name, c);
|
||||
else
|
||||
c(null);
|
||||
}
|
||||
|
||||
function findDoc(ts, doc, name) {
|
||||
for (var n in ts.docs) {
|
||||
var cur = ts.docs[n];
|
||||
if (cur.doc == doc) return cur;
|
||||
}
|
||||
if (!name) for (var i = 0;; ++i) {
|
||||
n = "[doc" + (i || "") + "]";
|
||||
if (!ts.docs[n]) { name = n; break; }
|
||||
}
|
||||
return ts.addDoc(name, doc);
|
||||
}
|
||||
|
||||
function trackChange(ts, doc, change) {
|
||||
var data = findDoc(ts, doc);
|
||||
|
||||
var argHints = ts.cachedArgHints;
|
||||
if (argHints && argHints.doc == doc && cmpPos(argHints.start, change.to) <= 0)
|
||||
ts.cachedArgHints = null;
|
||||
|
||||
var changed = data.changed;
|
||||
if (changed == null)
|
||||
data.changed = changed = {from: change.from.line, to: change.from.line};
|
||||
var end = change.from.line + (change.text.length - 1);
|
||||
if (change.from.line < changed.to) changed.to = changed.to - (change.to.line - end);
|
||||
if (end >= changed.to) changed.to = end + 1;
|
||||
if (changed.from > change.from.line) changed.from = change.from.line;
|
||||
|
||||
if (doc.lineCount() > bigDoc && change.to - changed.from > 100) setTimeout(function() {
|
||||
if (data.changed && data.changed.to - data.changed.from > 100) sendDoc(ts, data);
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function sendDoc(ts, doc) {
|
||||
ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {
|
||||
if (error) console.error(error);
|
||||
else doc.changed = null;
|
||||
});
|
||||
}
|
||||
|
||||
// Completion
|
||||
|
||||
function hint(ts, cm, c) {
|
||||
ts.request(cm, {type: "completions", types: true, docs: true, urls: true}, function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
var completions = [], after = "";
|
||||
var from = data.start, to = data.end;
|
||||
if (cm.getRange(Pos(from.line, from.ch - 2), from) == "[\"" &&
|
||||
cm.getRange(to, Pos(to.line, to.ch + 2)) != "\"]")
|
||||
after = "\"]";
|
||||
|
||||
for (var i = 0; i < data.completions.length; ++i) {
|
||||
var completion = data.completions[i], className = typeToIcon(completion.type);
|
||||
if (data.guess) className += " " + cls + "guess";
|
||||
completions.push({text: completion.name + after,
|
||||
displayText: completion.name,
|
||||
className: className,
|
||||
data: completion});
|
||||
}
|
||||
|
||||
var obj = {from: from, to: to, list: completions};
|
||||
var tooltip = null;
|
||||
CodeMirror.on(obj, "close", function() { remove(tooltip); });
|
||||
CodeMirror.on(obj, "update", function() { remove(tooltip); });
|
||||
CodeMirror.on(obj, "select", function(cur, node) {
|
||||
remove(tooltip);
|
||||
var content = ts.options.completionTip ? ts.options.completionTip(cur.data) : cur.data.doc;
|
||||
if (content) {
|
||||
tooltip = makeTooltip(node.parentNode.getBoundingClientRect().right + window.pageXOffset,
|
||||
node.getBoundingClientRect().top + window.pageYOffset, content);
|
||||
tooltip.className += " " + cls + "hint-doc";
|
||||
}
|
||||
});
|
||||
c(obj);
|
||||
});
|
||||
}
|
||||
|
||||
function typeToIcon(type) {
|
||||
var suffix;
|
||||
if (type == "?") suffix = "unknown";
|
||||
else if (type == "number" || type == "string" || type == "bool") suffix = type;
|
||||
else if (/^fn\(/.test(type)) suffix = "fn";
|
||||
else if (/^\[/.test(type)) suffix = "array";
|
||||
else suffix = "object";
|
||||
return cls + "completion " + cls + "completion-" + suffix;
|
||||
}
|
||||
|
||||
// Type queries
|
||||
|
||||
function showType(ts, cm, pos) {
|
||||
ts.request(cm, "type", function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
if (ts.options.typeTip) {
|
||||
var tip = ts.options.typeTip(data);
|
||||
} else {
|
||||
var tip = elt("span", null, elt("strong", null, data.type || "not found"));
|
||||
if (data.doc)
|
||||
tip.appendChild(document.createTextNode(" — " + data.doc));
|
||||
if (data.url) {
|
||||
tip.appendChild(document.createTextNode(" "));
|
||||
tip.appendChild(elt("a", null, "[docs]")).href = data.url;
|
||||
}
|
||||
}
|
||||
tempTooltip(cm, tip);
|
||||
}, pos);
|
||||
}
|
||||
|
||||
// Maintaining argument hints
|
||||
|
||||
function updateArgHints(ts, cm) {
|
||||
closeArgHints(ts);
|
||||
|
||||
if (cm.somethingSelected()) return;
|
||||
var state = cm.getTokenAt(cm.getCursor()).state;
|
||||
var inner = CodeMirror.innerMode(cm.getMode(), state);
|
||||
if (inner.mode.name != "javascript") return;
|
||||
var lex = inner.state.lexical;
|
||||
if (lex.info != "call") return;
|
||||
|
||||
var ch, pos = lex.pos || 0, tabSize = cm.getOption("tabSize");
|
||||
for (var line = cm.getCursor().line, e = Math.max(0, line - 9), found = false; line >= e; --line) {
|
||||
var str = cm.getLine(line), extra = 0;
|
||||
for (var pos = 0;;) {
|
||||
var tab = str.indexOf("\t", pos);
|
||||
if (tab == -1) break;
|
||||
extra += tabSize - (tab + extra) % tabSize - 1;
|
||||
pos = tab + 1;
|
||||
}
|
||||
ch = lex.column - extra;
|
||||
if (str.charAt(ch) == "(") {found = true; break;}
|
||||
}
|
||||
if (!found) return;
|
||||
|
||||
var start = Pos(line, ch);
|
||||
var cache = ts.cachedArgHints;
|
||||
if (cache && cache.doc == cm.getDoc() && cmpPos(start, cache.start) == 0)
|
||||
return showArgHints(ts, cm, pos);
|
||||
|
||||
ts.request(cm, {type: "type", preferFunction: true, end: start}, function(error, data) {
|
||||
if (error || !data.type || !(/^fn\(/).test(data.type)) return;
|
||||
ts.cachedArgHints = {
|
||||
start: pos,
|
||||
type: parseFnType(data.type),
|
||||
name: data.exprName || data.name || "fn",
|
||||
guess: data.guess,
|
||||
doc: cm.getDoc()
|
||||
};
|
||||
showArgHints(ts, cm, pos);
|
||||
});
|
||||
}
|
||||
|
||||
function showArgHints(ts, cm, pos) {
|
||||
closeArgHints(ts);
|
||||
|
||||
var cache = ts.cachedArgHints, tp = cache.type;
|
||||
var tip = elt("span", cache.guess ? cls + "fhint-guess" : null,
|
||||
elt("span", cls + "fname", cache.name), "(");
|
||||
for (var i = 0; i < tp.args.length; ++i) {
|
||||
if (i) tip.appendChild(document.createTextNode(", "));
|
||||
var arg = tp.args[i];
|
||||
tip.appendChild(elt("span", cls + "farg" + (i == pos ? " " + cls + "farg-current" : ""), arg.name || "?"));
|
||||
if (arg.type != "?") {
|
||||
tip.appendChild(document.createTextNode(":\u00a0"));
|
||||
tip.appendChild(elt("span", cls + "type", arg.type));
|
||||
}
|
||||
}
|
||||
tip.appendChild(document.createTextNode(tp.rettype ? ") ->\u00a0" : ")"));
|
||||
if (tp.rettype) tip.appendChild(elt("span", cls + "type", tp.rettype));
|
||||
var place = cm.cursorCoords(null, "page");
|
||||
ts.activeArgHints = makeTooltip(place.right + 1, place.bottom, tip);
|
||||
}
|
||||
|
||||
function parseFnType(text) {
|
||||
var args = [], pos = 3;
|
||||
|
||||
function skipMatching(upto) {
|
||||
var depth = 0, start = pos;
|
||||
for (;;) {
|
||||
var next = text.charAt(pos);
|
||||
if (upto.test(next) && !depth) return text.slice(start, pos);
|
||||
if (/[{\[\(]/.test(next)) ++depth;
|
||||
else if (/[}\]\)]/.test(next)) --depth;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse arguments
|
||||
if (text.charAt(pos) != ")") for (;;) {
|
||||
var name = text.slice(pos).match(/^([^, \(\[\{]+): /);
|
||||
if (name) {
|
||||
pos += name[0].length;
|
||||
name = name[1];
|
||||
}
|
||||
args.push({name: name, type: skipMatching(/[\),]/)});
|
||||
if (text.charAt(pos) == ")") break;
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
var rettype = text.slice(pos).match(/^\) -> (.*)$/);
|
||||
|
||||
return {args: args, rettype: rettype && rettype[1]};
|
||||
}
|
||||
|
||||
// Moving to the definition of something
|
||||
|
||||
function jumpToDef(ts, cm) {
|
||||
function inner(varName) {
|
||||
var req = {type: "definition", variable: varName || null};
|
||||
var doc = findDoc(ts, cm.getDoc());
|
||||
ts.server.request(buildRequest(ts, doc, req), function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
if (!data.file && data.url) { window.open(data.url); return; }
|
||||
|
||||
if (data.file) {
|
||||
var localDoc = ts.docs[data.file], found;
|
||||
if (localDoc && (found = findContext(localDoc.doc, data))) {
|
||||
ts.jumpStack.push({file: doc.name,
|
||||
start: cm.getCursor("from"),
|
||||
end: cm.getCursor("to")});
|
||||
moveTo(ts, doc, localDoc, found.start, found.end);
|
||||
return;
|
||||
}
|
||||
}
|
||||
showError(ts, cm, "Could not find a definition.");
|
||||
});
|
||||
}
|
||||
|
||||
if (!atInterestingExpression(cm))
|
||||
dialog(cm, "Jump to variable", function(name) { if (name) inner(name); });
|
||||
else
|
||||
inner();
|
||||
}
|
||||
|
||||
function jumpBack(ts, cm) {
|
||||
var pos = ts.jumpStack.pop(), doc = pos && ts.docs[pos.file];
|
||||
if (!doc) return;
|
||||
moveTo(ts, findDoc(ts, cm.getDoc()), doc, pos.start, pos.end);
|
||||
}
|
||||
|
||||
function moveTo(ts, curDoc, doc, start, end) {
|
||||
doc.doc.setSelection(end, start);
|
||||
if (curDoc != doc && ts.options.switchToDoc) {
|
||||
closeArgHints(ts);
|
||||
ts.options.switchToDoc(doc.name);
|
||||
}
|
||||
}
|
||||
|
||||
// The {line,ch} representation of positions makes this rather awkward.
|
||||
function findContext(doc, data) {
|
||||
var before = data.context.slice(0, data.contextOffset).split("\n");
|
||||
var startLine = data.start.line - (before.length - 1);
|
||||
var start = Pos(startLine, (before.length == 1 ? data.start.ch : doc.getLine(startLine).length) - before[0].length);
|
||||
|
||||
var text = doc.getLine(startLine).slice(start.ch);
|
||||
for (var cur = startLine + 1; cur < doc.lineCount() && text.length < data.context.length; ++cur)
|
||||
text += "\n" + doc.getLine(cur);
|
||||
if (text.slice(0, data.context.length) == data.context) return data;
|
||||
|
||||
var cursor = doc.getSearchCursor(data.context, 0, false);
|
||||
var nearest, nearestDist = Infinity;
|
||||
while (cursor.findNext()) {
|
||||
var from = cursor.from(), dist = Math.abs(from.line - start.line) * 10000;
|
||||
if (!dist) dist = Math.abs(from.ch - start.ch);
|
||||
if (dist < nearestDist) { nearest = from; nearestDist = dist; }
|
||||
}
|
||||
if (!nearest) return null;
|
||||
|
||||
if (before.length == 1)
|
||||
nearest.ch += before[0].length;
|
||||
else
|
||||
nearest = Pos(nearest.line + (before.length - 1), before[before.length - 1].length);
|
||||
if (data.start.line == data.end.line)
|
||||
var end = Pos(nearest.line, nearest.ch + (data.end.ch - data.start.ch));
|
||||
else
|
||||
var end = Pos(nearest.line + (data.end.line - data.start.line), data.end.ch);
|
||||
return {start: nearest, end: end};
|
||||
}
|
||||
|
||||
function atInterestingExpression(cm) {
|
||||
var pos = cm.getCursor("end"), tok = cm.getTokenAt(pos);
|
||||
if (tok.start < pos.ch && (tok.type == "comment" || tok.type == "string")) return false;
|
||||
return /\w/.test(cm.getLine(pos.line).slice(Math.max(pos.ch - 1, 0), pos.ch + 1));
|
||||
}
|
||||
|
||||
// Variable renaming
|
||||
|
||||
function rename(ts, cm) {
|
||||
var token = cm.getTokenAt(cm.getCursor());
|
||||
if (!/\w/.test(token.string)) showError(ts, cm, "Not at a variable");
|
||||
dialog(cm, "New name for " + token.string, function(newName) {
|
||||
ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {
|
||||
if (error) return showError(ts, cm, error);
|
||||
applyChanges(ts, data.changes);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var nextChangeOrig = 0;
|
||||
function applyChanges(ts, changes) {
|
||||
var perFile = Object.create(null);
|
||||
for (var i = 0; i < changes.length; ++i) {
|
||||
var ch = changes[i];
|
||||
(perFile[ch.file] || (perFile[ch.file] = [])).push(ch);
|
||||
}
|
||||
for (var file in perFile) {
|
||||
var known = ts.docs[file], chs = perFile[file];;
|
||||
if (!known) continue;
|
||||
chs.sort(function(a, b) { return cmpPos(b.start, a.start); });
|
||||
var origin = "*rename" + (++nextChangeOrig);
|
||||
for (var i = 0; i < chs.length; ++i) {
|
||||
var ch = chs[i];
|
||||
known.doc.replaceRange(ch.text, ch.start, ch.end, origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generic request-building helper
|
||||
|
||||
function buildRequest(ts, doc, query, pos) {
|
||||
var files = [], offsetLines = 0, allowFragments = !query.fullDocs;
|
||||
if (!allowFragments) delete query.fullDocs;
|
||||
if (typeof query == "string") query = {type: query};
|
||||
query.lineCharPositions = true;
|
||||
if (query.end == null) {
|
||||
query.end = pos || doc.doc.getCursor("end");
|
||||
if (doc.doc.somethingSelected())
|
||||
query.start = doc.doc.getCursor("start");
|
||||
}
|
||||
var startPos = query.start || query.end;
|
||||
|
||||
if (doc.changed) {
|
||||
if (doc.doc.lineCount() > bigDoc && allowFragments !== false &&
|
||||
doc.changed.to - doc.changed.from < 100 &&
|
||||
doc.changed.from <= startPos.line && doc.changed.to > query.end.line) {
|
||||
files.push(getFragmentAround(doc, startPos, query.end));
|
||||
query.file = "#0";
|
||||
var offsetLines = files[0].offsetLines;
|
||||
if (query.start != null) query.start = Pos(query.start.line - -offsetLines, query.start.ch);
|
||||
query.end = Pos(query.end.line - offsetLines, query.end.ch);
|
||||
} else {
|
||||
files.push({type: "full",
|
||||
name: doc.name,
|
||||
text: docValue(ts, doc)});
|
||||
query.file = doc.name;
|
||||
doc.changed = null;
|
||||
}
|
||||
} else {
|
||||
query.file = doc.name;
|
||||
}
|
||||
for (var name in ts.docs) {
|
||||
var cur = ts.docs[name];
|
||||
if (cur.changed && cur != doc) {
|
||||
files.push({type: "full", name: cur.name, text: docValue(ts, cur)});
|
||||
cur.changed = null;
|
||||
}
|
||||
}
|
||||
|
||||
return {query: query, files: files};
|
||||
}
|
||||
|
||||
function getFragmentAround(data, start, end) {
|
||||
var doc = data.doc;
|
||||
var minIndent = null, minLine = null, endLine, tabSize = 4;
|
||||
for (var p = start.line - 1, min = Math.max(0, p - 50); p >= min; --p) {
|
||||
var line = doc.getLine(p), fn = line.search(/\bfunction\b/);
|
||||
if (fn < 0) continue;
|
||||
var indent = CodeMirror.countColumn(line, null, tabSize);
|
||||
if (minIndent != null && minIndent <= indent) continue;
|
||||
minIndent = indent;
|
||||
minLine = p;
|
||||
}
|
||||
if (minLine == null) minLine = min;
|
||||
var max = Math.min(doc.lastLine(), end.line + 20);
|
||||
if (minIndent == null || minIndent == CodeMirror.countColumn(doc.getLine(start.line), null, tabSize))
|
||||
endLine = max;
|
||||
else for (endLine = end.line + 1; endLine < max; ++endLine) {
|
||||
var indent = CodeMirror.countColumn(doc.getLine(endLine), null, tabSize);
|
||||
if (indent <= minIndent) break;
|
||||
}
|
||||
var from = Pos(minLine, 0);
|
||||
|
||||
return {type: "part",
|
||||
name: data.name,
|
||||
offsetLines: from.line,
|
||||
text: doc.getRange(from, Pos(endLine, 0))};
|
||||
}
|
||||
|
||||
// Generic utilities
|
||||
|
||||
function cmpPos(a, b) { return a.line - b.line || a.ch - b.ch; }
|
||||
|
||||
function elt(tagname, cls /*, ... elts*/) {
|
||||
var e = document.createElement(tagname);
|
||||
if (cls) e.className = cls;
|
||||
for (var i = 2; i < arguments.length; ++i) {
|
||||
var elt = arguments[i];
|
||||
if (typeof elt == "string") elt = document.createTextNode(elt);
|
||||
e.appendChild(elt);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
function dialog(cm, text, f) {
|
||||
if (cm.openDialog)
|
||||
cm.openDialog(text + ": <input type=text>", f);
|
||||
else
|
||||
f(prompt(text, ""));
|
||||
}
|
||||
|
||||
// Tooltips
|
||||
|
||||
function tempTooltip(cm, content) {
|
||||
var where = cm.cursorCoords();
|
||||
var tip = makeTooltip(where.right + 1, where.bottom, content);
|
||||
function clear() {
|
||||
if (!tip.parentNode) return;
|
||||
cm.off("cursorActivity", clear);
|
||||
fadeOut(tip);
|
||||
}
|
||||
setTimeout(clear, 1700);
|
||||
cm.on("cursorActivity", clear);
|
||||
}
|
||||
|
||||
function makeTooltip(x, y, content) {
|
||||
var node = elt("div", cls + "tooltip", content);
|
||||
node.style.left = x + "px";
|
||||
node.style.top = y + "px";
|
||||
document.body.appendChild(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
function remove(node) {
|
||||
var p = node && node.parentNode;
|
||||
if (p) p.removeChild(node);
|
||||
}
|
||||
|
||||
function fadeOut(tooltip) {
|
||||
tooltip.style.opacity = "0";
|
||||
setTimeout(function() { remove(tooltip); }, 1100);
|
||||
}
|
||||
|
||||
function showError(ts, cm, msg) {
|
||||
if (ts.options.showError)
|
||||
ts.options.showError(cm, msg);
|
||||
else
|
||||
tempTooltip(cm, String(msg));
|
||||
}
|
||||
|
||||
function closeArgHints(ts) {
|
||||
if (ts.activeArgHints) { remove(ts.activeArgHints); ts.activeArgHints = null; }
|
||||
}
|
||||
|
||||
function docValue(ts, doc) {
|
||||
var val = doc.doc.getValue();
|
||||
if (ts.options.fileFilter) val = ts.options.fileFilter(val, doc.name, doc.doc);
|
||||
return val;
|
||||
}
|
||||
|
||||
// Worker wrapper
|
||||
|
||||
function WorkerServer(ts) {
|
||||
var worker = new Worker(ts.options.workerScript);
|
||||
worker.postMessage({type: "init",
|
||||
defs: ts.options.defs,
|
||||
plugins: ts.options.plugins,
|
||||
scripts: ts.options.workerDeps});
|
||||
var msgId = 0, pending = {};
|
||||
|
||||
function send(data, c) {
|
||||
if (c) {
|
||||
data.id = ++msgId;
|
||||
pending[msgId] = c;
|
||||
}
|
||||
worker.postMessage(data);
|
||||
}
|
||||
worker.onmessage = function(e) {
|
||||
var data = e.data;
|
||||
if (data.type == "getFile") {
|
||||
getFile(ts, data.name, function(err, text) {
|
||||
send({type: "getFile", err: String(err), text: text, id: data.id});
|
||||
});
|
||||
} else if (data.type == "debug") {
|
||||
console.log(data.message);
|
||||
} else if (data.id && pending[data.id]) {
|
||||
pending[data.id](data.err, data.body);
|
||||
delete pending[data.id];
|
||||
}
|
||||
};
|
||||
worker.onerror = function(e) {
|
||||
for (var id in pending) pending[id](e);
|
||||
pending = {};
|
||||
};
|
||||
|
||||
this.addFile = function(name, text) { send({type: "add", name: name, text: text}); };
|
||||
this.delFile = function(name) { send({type: "del", name: name}); };
|
||||
this.request = function(body, c) { send({type: "req", body: body}, c); };
|
||||
}
|
||||
})();
|
41
plugins/codemirror/codemirror/addon/tern/worker.js
vendored
Normal file
41
plugins/codemirror/codemirror/addon/tern/worker.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// declare global: tern, server
|
||||
|
||||
var server;
|
||||
|
||||
this.onmessage = function(e) {
|
||||
var data = e.data;
|
||||
switch (data.type) {
|
||||
case "init": return startServer(data.defs, data.plugins, data.scripts);
|
||||
case "add": return server.addFile(data.name, data.text);
|
||||
case "del": return server.delFile(data.name);
|
||||
case "req": return server.request(data.body, function(err, reqData) {
|
||||
postMessage({id: data.id, body: reqData, err: err && String(err)});
|
||||
});
|
||||
case "getFile":
|
||||
var c = pending[data.id];
|
||||
delete pending[data.id];
|
||||
return c(data.err, data.text);
|
||||
default: throw new Error("Unknown message type: " + data.type);
|
||||
}
|
||||
};
|
||||
|
||||
var nextId = 0, pending = {};
|
||||
function getFile(file, c) {
|
||||
postMessage({type: "getFile", name: file, id: ++nextId});
|
||||
pending[nextId] = c;
|
||||
}
|
||||
|
||||
function startServer(defs, plugins, scripts) {
|
||||
if (scripts) importScripts.apply(null, scripts);
|
||||
|
||||
server = new tern.Server({
|
||||
getFile: getFile,
|
||||
async: true,
|
||||
defs: defs,
|
||||
plugins: plugins
|
||||
});
|
||||
}
|
||||
|
||||
var console = {
|
||||
log: function(v) { postMessage({type: "debug", message: v}); }
|
||||
};
|
99
plugins/codemirror/codemirror/addon/wrap/hardwrap.js
vendored
Normal file
99
plugins/codemirror/codemirror/addon/wrap/hardwrap.js
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function findParagraph(cm, pos, options) {
|
||||
var startRE = options.paragraphStart || cm.getHelper(pos, "paragraphStart");
|
||||
for (var start = pos.line, first = cm.firstLine(); start > first; --start) {
|
||||
var line = cm.getLine(start);
|
||||
if (startRE && startRE.test(line)) break;
|
||||
if (!/\S/.test(line)) { ++start; break; }
|
||||
}
|
||||
var endRE = options.paragraphEnd || cm.getHelper(pos, "paragraphEnd");
|
||||
for (var end = pos.line + 1, last = cm.lastLine(); end <= last; ++end) {
|
||||
var line = cm.getLine(end);
|
||||
if (endRE && endRE.test(line)) { ++end; break; }
|
||||
if (!/\S/.test(line)) break;
|
||||
}
|
||||
return {from: start, to: end};
|
||||
}
|
||||
|
||||
function findBreakPoint(text, column, wrapOn, killTrailingSpace) {
|
||||
for (var at = column; at > 0; --at)
|
||||
if (wrapOn.test(text.slice(at - 1, at + 1))) break;
|
||||
if (at == 0) at = column;
|
||||
var endOfText = at;
|
||||
if (killTrailingSpace)
|
||||
while (text.charAt(endOfText - 1) == " ") --endOfText;
|
||||
return {from: endOfText, to: at};
|
||||
}
|
||||
|
||||
function wrapRange(cm, from, to, options) {
|
||||
from = cm.clipPos(from); to = cm.clipPos(to);
|
||||
var column = options.column || 80;
|
||||
var wrapOn = options.wrapOn || /\s\S|-[^\.\d]/;
|
||||
var killTrailing = options.killTrailingSpace !== false;
|
||||
var changes = [], curLine = "", curNo = from.line;
|
||||
var lines = cm.getRange(from, to, false);
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
var text = lines[i], oldLen = curLine.length, spaceInserted = 0;
|
||||
if (curLine && text && !wrapOn.test(curLine.charAt(curLine.length - 1) + text.charAt(0))) {
|
||||
curLine += " ";
|
||||
spaceInserted = 1;
|
||||
}
|
||||
curLine += text;
|
||||
if (i) {
|
||||
var firstBreak = curLine.length > column && findBreakPoint(curLine, column, wrapOn, killTrailing);
|
||||
// If this isn't broken, or is broken at a different point, remove old break
|
||||
if (!firstBreak || firstBreak.from != oldLen || firstBreak.to != oldLen + spaceInserted) {
|
||||
changes.push({text: spaceInserted ? " " : "",
|
||||
from: Pos(curNo, oldLen),
|
||||
to: Pos(curNo + 1, 0)});
|
||||
} else {
|
||||
curLine = text;
|
||||
++curNo;
|
||||
}
|
||||
}
|
||||
while (curLine.length > column) {
|
||||
var bp = findBreakPoint(curLine, column, wrapOn, killTrailing);
|
||||
changes.push({text: "\n",
|
||||
from: Pos(curNo, bp.from),
|
||||
to: Pos(curNo, bp.to)});
|
||||
curLine = curLine.slice(bp.to);
|
||||
++curNo;
|
||||
}
|
||||
}
|
||||
if (changes.length) cm.operation(function() {
|
||||
for (var i = 0; i < changes.length; ++i) {
|
||||
var change = changes[i];
|
||||
cm.replaceRange(change.text, change.from, change.to);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CodeMirror.defineExtension("wrapParagraph", function(pos, options) {
|
||||
options = options || {};
|
||||
if (!pos) pos = this.getCursor();
|
||||
var para = findParagraph(this, pos, options);
|
||||
wrapRange(this, Pos(para.from, 0), Pos(para.to - 1), options);
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("wrapRange", function(from, to, options) {
|
||||
wrapRange(this, from, to, options || {});
|
||||
});
|
||||
|
||||
CodeMirror.defineExtension("wrapParagraphsInRange", function(from, to, options) {
|
||||
options = options || {};
|
||||
var cm = this, paras = [];
|
||||
for (var line = from.line; line <= to.line;) {
|
||||
var para = findParagraph(cm, Pos(line, 0), options);
|
||||
paras.push(para);
|
||||
line = para.to;
|
||||
}
|
||||
if (paras.length) cm.operation(function() {
|
||||
for (var i = paras.length - 1; i >= 0; --i)
|
||||
wrapRange(cm, Pos(paras[i].from, 0), Pos(paras[i].to - 1), options);
|
||||
});
|
||||
});
|
||||
})();
|
6
plugins/codemirror/codemirror/bin/authors.sh
Normal file
6
plugins/codemirror/codemirror/bin/authors.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
# Combine existing list of authors with everyone known in git, sort, add header.
|
||||
tail --lines=+3 AUTHORS > AUTHORS.tmp
|
||||
git log --format='%aN' >> AUTHORS.tmp
|
||||
echo -e "List of CodeMirror contributors. Updated before every release.\n" > AUTHORS
|
||||
sort -u AUTHORS.tmp >> AUTHORS
|
||||
rm -f AUTHORS.tmp
|
92
plugins/codemirror/codemirror/bin/compress
Normal file
92
plugins/codemirror/codemirror/bin/compress
Normal file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Compression helper for CodeMirror
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// bin/compress codemirror runmode javascript xml
|
||||
//
|
||||
// Will take lib/codemirror.js, addon/runmode/runmode.js,
|
||||
// mode/javascript/javascript.js, and mode/xml/xml.js, run them though
|
||||
// the online minifier at http://marijnhaverbeke.nl/uglifyjs, and spit
|
||||
// out the result.
|
||||
//
|
||||
// bin/compress codemirror --local /path/to/bin/UglifyJS
|
||||
//
|
||||
// Will use a local minifier instead of the online default one.
|
||||
//
|
||||
// Script files are specified without .js ending. Prefixing them with
|
||||
// their full (local) path is optional. So you may say lib/codemirror
|
||||
// or mode/xml/xml to be more precise. In fact, even the .js suffix
|
||||
// may be speficied, if wanted.
|
||||
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
|
||||
function help(ok) {
|
||||
console.log("usage: " + process.argv[1] + " [--local /path/to/uglifyjs] files...");
|
||||
process.exit(ok ? 0 : 1);
|
||||
}
|
||||
|
||||
var local = null, args = [], extraArgs = null, files = [], blob = "";
|
||||
|
||||
for (var i = 2; i < process.argv.length; ++i) {
|
||||
var arg = process.argv[i];
|
||||
if (arg == "--local" && i + 1 < process.argv.length) {
|
||||
var parts = process.argv[++i].split(/\s+/);
|
||||
local = parts[0];
|
||||
extraArgs = parts.slice(1);
|
||||
if (!extraArgs.length) extraArgs = ["-c", "-m"];
|
||||
} else if (arg == "--help") {
|
||||
help(true);
|
||||
} else if (arg[0] != "-") {
|
||||
files.push({name: arg, re: new RegExp("(?:\\/|^)" + arg + (/\.js$/.test(arg) ? "$" : "\\.js$"))});
|
||||
} else help(false);
|
||||
}
|
||||
|
||||
function walk(dir) {
|
||||
fs.readdirSync(dir).forEach(function(fname) {
|
||||
if (/^[_\.]/.test(fname)) return;
|
||||
var file = dir + fname;
|
||||
if (fs.statSync(file).isDirectory()) return walk(file + "/");
|
||||
if (files.some(function(spec, i) {
|
||||
var match = spec.re.test(file);
|
||||
if (match) files.splice(i, 1);
|
||||
return match;
|
||||
})) {
|
||||
if (local) args.push(file);
|
||||
else blob += fs.readFileSync(file, "utf8");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
walk("lib/");
|
||||
walk("addon/");
|
||||
walk("mode/");
|
||||
|
||||
if (!local && !blob) help(false);
|
||||
|
||||
if (files.length) {
|
||||
console.log("Some speficied files were not found: " +
|
||||
files.map(function(a){return a.name;}).join(", "));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (local) {
|
||||
require("child_process").spawn(local, args.concat(extraArgs), {stdio: ["ignore", process.stdout, process.stderr]});
|
||||
} else {
|
||||
var data = new Buffer("js_code=" + require("querystring").escape(blob), "utf8");
|
||||
var req = require("http").request({
|
||||
host: "marijnhaverbeke.nl",
|
||||
port: 80,
|
||||
method: "POST",
|
||||
path: "/uglifyjs",
|
||||
headers: {"content-type": "application/x-www-form-urlencoded",
|
||||
"content-length": data.length}
|
||||
});
|
||||
req.on("response", function(resp) {
|
||||
resp.on("data", function (chunk) { process.stdout.write(chunk); });
|
||||
});
|
||||
req.end(data);
|
||||
}
|
16
plugins/codemirror/codemirror/bin/lint
Normal file
16
plugins/codemirror/codemirror/bin/lint
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var lint = require("../test/lint/lint"),
|
||||
path = require("path");
|
||||
|
||||
if (process.argv.length > 2) {
|
||||
lint.checkDir(process.argv[2]);
|
||||
} else {
|
||||
process.chdir(path.resolve(__dirname, ".."));
|
||||
lint.checkDir("lib");
|
||||
lint.checkDir("mode");
|
||||
lint.checkDir("addon");
|
||||
lint.checkDir("keymap");
|
||||
}
|
||||
|
||||
process.exit(lint.success() ? 0 : 1);
|
61
plugins/codemirror/codemirror/bin/source-highlight
Normal file
61
plugins/codemirror/codemirror/bin/source-highlight
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Simple command-line code highlighting tool. Reads code from stdin,
|
||||
// spits html to stdout. For example:
|
||||
//
|
||||
// echo 'function foo(a) { return a; }' | bin/source-highlight -s javascript
|
||||
// bin/source-highlight -s
|
||||
|
||||
var fs = require("fs");
|
||||
|
||||
CodeMirror = require("../addon/runmode/runmode.node.js");
|
||||
require("../mode/meta.js");
|
||||
|
||||
var sPos = process.argv.indexOf("-s");
|
||||
if (sPos == -1 || sPos == process.argv.length - 1) {
|
||||
console.error("Usage: source-highlight -s language");
|
||||
process.exit(1);
|
||||
}
|
||||
var lang = process.argv[sPos + 1].toLowerCase(), modeName = lang;
|
||||
CodeMirror.modeInfo.forEach(function(info) {
|
||||
if (info.mime == lang) {
|
||||
modeName = info.mode;
|
||||
} else if (info.name.toLowerCase() == lang) {
|
||||
modeName = info.mode;
|
||||
lang = info.mime;
|
||||
}
|
||||
});
|
||||
|
||||
function ensureMode(name) {
|
||||
if (CodeMirror.modes[name] || name == "null") return;
|
||||
try {
|
||||
require("../mode/" + name + "/" + name + ".js");
|
||||
} catch(e) {
|
||||
console.error("Could not load mode " + name + ".");
|
||||
process.exit(1);
|
||||
}
|
||||
var obj = CodeMirror.modes[name];
|
||||
if (obj.dependencies) obj.dependencies.forEach(ensureMode);
|
||||
}
|
||||
ensureMode(modeName);
|
||||
|
||||
function esc(str) {
|
||||
return str.replace(/[<&]/, function(ch) { return ch == "&" ? "&" : "<"; });
|
||||
}
|
||||
|
||||
var code = fs.readFileSync("/dev/stdin", "utf8");
|
||||
var curStyle = null, accum = "";
|
||||
function flush() {
|
||||
if (curStyle) process.stdout.write("<span class=\"" + curStyle.replace(/(^|\s+)/g, "$1cm-") + "\">" + esc(accum) + "</span>");
|
||||
else process.stdout.write(esc(accum));
|
||||
}
|
||||
|
||||
CodeMirror.runMode(code, lang, function(text, style) {
|
||||
if (style != curStyle) {
|
||||
flush();
|
||||
curStyle = style; accum = text;
|
||||
} else {
|
||||
accum += text;
|
||||
}
|
||||
});
|
||||
flush();
|
15
plugins/codemirror/codemirror/bower.json
Normal file
15
plugins/codemirror/codemirror/bower.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "CodeMirror",
|
||||
"main": ["lib/codemirror.js", "lib/codemirror.css"],
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"components",
|
||||
"bin",
|
||||
"demo",
|
||||
"doc",
|
||||
"test",
|
||||
"index.html",
|
||||
"package.json"
|
||||
]
|
||||
}
|
78
plugins/codemirror/codemirror/demo/activeline.html
vendored
Normal file
78
plugins/codemirror/codemirror/demo/activeline.html
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Active Line Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../addon/selection/active-line.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Active Line</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Active Line Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"
|
||||
xmlns:georss="http://www.georss.org/georss"
|
||||
xmlns:twitter="http://api.twitter.com">
|
||||
<channel>
|
||||
<title>Twitter / codemirror</title>
|
||||
<link>http://twitter.com/codemirror</link>
|
||||
<atom:link type="application/rss+xml"
|
||||
href="http://twitter.com/statuses/user_timeline/242283288.rss" rel="self"/>
|
||||
<description>Twitter updates from CodeMirror / codemirror.</description>
|
||||
<language>en-us</language>
|
||||
<ttl>40</ttl>
|
||||
<item>
|
||||
<title>codemirror: http://cloud-ide.com — they're springing up like mushrooms. This one
|
||||
uses CodeMirror as its editor.</title>
|
||||
<description>codemirror: http://cloud-ide.com — they're springing up like mushrooms. This
|
||||
one uses CodeMirror as its editor.</description>
|
||||
<pubDate>Thu, 17 Mar 2011 23:34:47 +0000</pubDate>
|
||||
<guid>http://twitter.com/codemirror/statuses/48527733722058752</guid>
|
||||
<link>http://twitter.com/codemirror/statuses/48527733722058752</link>
|
||||
<twitter:source>web</twitter:source>
|
||||
<twitter:place/>
|
||||
</item>
|
||||
<item>
|
||||
<title>codemirror: Posted a description of the CodeMirror 2 internals at
|
||||
http://codemirror.net/2/internals.html</title>
|
||||
<description>codemirror: Posted a description of the CodeMirror 2 internals at
|
||||
http://codemirror.net/2/internals.html</description>
|
||||
<pubDate>Wed, 02 Mar 2011 12:15:09 +0000</pubDate>
|
||||
<guid>http://twitter.com/codemirror/statuses/42920879788789760</guid>
|
||||
<link>http://twitter.com/codemirror/statuses/42920879788789760</link>
|
||||
<twitter:source>web</twitter:source>
|
||||
<twitter:place/>
|
||||
</item>
|
||||
</channel>
|
||||
</rss></textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "application/xml",
|
||||
styleActiveLine: true,
|
||||
lineNumbers: true,
|
||||
lineWrapping: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Styling the current cursor line.</p>
|
||||
|
||||
</article>
|
79
plugins/codemirror/codemirror/demo/anywordhint.html
vendored
Normal file
79
plugins/codemirror/codemirror/demo/anywordhint.html
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Any Word Completion Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/hint/show-hint.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/hint/show-hint.js"></script>
|
||||
<script src="../addon/hint/anyword-hint.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Any Word Completion</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Any Word Completion Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var WORD = /[\w$]+/g, RANGE = 500;
|
||||
|
||||
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
|
||||
var word = options && options.word || WORD;
|
||||
var range = options && options.range || RANGE;
|
||||
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
|
||||
var start = cur.ch, end = start;
|
||||
while (end < curLine.length && word.test(curLine.charAt(end))) ++end;
|
||||
while (start && word.test(curLine.charAt(start - 1))) --start;
|
||||
var curWord = start != end && curLine.slice(start, end);
|
||||
|
||||
var list = [], seen = {};
|
||||
function scan(dir) {
|
||||
var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
|
||||
for (; line != end; line += dir) {
|
||||
var text = editor.getLine(line), m;
|
||||
word.lastIndex = 0;
|
||||
while (m = word.exec(text)) {
|
||||
if ((!curWord || m[0].indexOf(curWord) == 0) && !seen.hasOwnProperty(m[0])) {
|
||||
seen[m[0]] = true;
|
||||
list.push(m[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scan(-1);
|
||||
scan(1);
|
||||
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
|
||||
});
|
||||
})();
|
||||
</textarea></form>
|
||||
|
||||
<p>Press <strong>ctrl-space</strong> to activate autocompletion. The
|
||||
completion uses
|
||||
the <a href="../doc/manual.html#addon_anyword-hint">anyword-hint.js</a>
|
||||
module, which simply looks at nearby words in the buffer and completes
|
||||
to those.</p>
|
||||
|
||||
<script>
|
||||
CodeMirror.commands.autocomplete = function(cm) {
|
||||
CodeMirror.showHint(cm, CodeMirror.hint.anyword);
|
||||
}
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"}
|
||||
});
|
||||
</script>
|
||||
</article>
|
74
plugins/codemirror/codemirror/demo/bidi.html
vendored
Normal file
74
plugins/codemirror/codemirror/demo/bidi.html
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Bi-directional Text Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Bi-directional Text</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Bi-directional Text Demo</h2>
|
||||
<form><textarea id="code" name="code"><!-- Piece of the CodeMirror manual, 'translated' into Arabic by
|
||||
Google Translate -->
|
||||
|
||||
<dl>
|
||||
<dt id=option_value><code>value (string or Doc)</code></dt>
|
||||
<dd>قيمة البداية المحرر. يمكن أن تكون سلسلة، أو. كائن مستند.</dd>
|
||||
<dt id=option_mode><code>mode (string or object)</code></dt>
|
||||
<dd>وضع الاستخدام. عندما لا تعطى، وهذا الافتراضي إلى الطريقة الاولى
|
||||
التي تم تحميلها. قد يكون من سلسلة، والتي إما أسماء أو ببساطة هو وضع
|
||||
MIME نوع المرتبطة اسطة. بدلا من ذلك، قد يكون من كائن يحتوي على
|
||||
خيارات التكوين لواسطة، مع <code>name</code> الخاصية التي وضع أسماء
|
||||
(على سبيل المثال <code>{name: "javascript", json: true}</code>).
|
||||
صفحات التجريبي لكل وضع تحتوي على معلومات حول ما معلمات تكوين وضع
|
||||
يدعمها. يمكنك أن تطلب CodeMirror التي تم تعريفها طرق وأنواع MIME
|
||||
الكشف على <code>CodeMirror.modes</code>
|
||||
و <code>CodeMirror.mimeModes</code> الكائنات. وضع خرائط الأسماء
|
||||
الأولى لمنشئات الخاصة بهم، وخرائط لأنواع MIME 2 المواصفات
|
||||
واسطة.</dd>
|
||||
<dt id=option_theme><code>theme (string)</code></dt>
|
||||
<dd>موضوع لنمط المحرر مع. يجب عليك التأكد من الملف CSS تحديد
|
||||
المقابلة <code>.cm-s-[name]</code> يتم تحميل أنماط (انظر
|
||||
<a href=../theme/><code>theme</code></a> الدليل في التوزيع).
|
||||
الافتراضي هو <code>"default"</code> ، والتي تم تضمينها في
|
||||
الألوان <code>codemirror.css</code>. فمن الممكن استخدام فئات متعددة
|
||||
في تطبيق السمات مرة واحدة على سبيل المثال <code>"foo bar"</code>
|
||||
سيتم تعيين كل من <code>cm-s-foo</code> و <code>cm-s-bar</code>
|
||||
الطبقات إلى المحرر.</dd>
|
||||
</dl>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "text/html",
|
||||
lineNumbers: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Demonstration of bi-directional text support. See
|
||||
the <a href="http://marijnhaverbeke.nl/blog/cursor-in-bidi-text.html">related
|
||||
blog post</a> for more background.</p>
|
||||
|
||||
<p><strong>Note:</strong> There is
|
||||
a <a href="https://github.com/marijnh/CodeMirror/issues/1757">known
|
||||
bug</a> with cursor motion and mouse clicks in bi-directional lines
|
||||
that are line wrapped.</p>
|
||||
|
||||
</article>
|
86
plugins/codemirror/codemirror/demo/btree.html
vendored
Normal file
86
plugins/codemirror/codemirror/demo/btree.html
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: B-Tree visualization</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<style type="text/css">
|
||||
.lineblock { display: inline-block; margin: 1px; height: 5px; }
|
||||
.CodeMirror {border: 1px solid #aaa; height: 400px}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">B-Tree visualization</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>B-Tree visualization</h2>
|
||||
<form><textarea id="code" name="code">type here, see a summary of the document b-tree below</textarea></form>
|
||||
</div>
|
||||
<div style="display: inline-block; height: 402px; overflow-y: auto" id="output"></div>
|
||||
</div>
|
||||
|
||||
<script id="me">
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
lineWrapping: true
|
||||
});
|
||||
var updateTimeout;
|
||||
editor.on("change", function(cm) {
|
||||
clearTimeout(updateTimeout);
|
||||
updateTimeout = setTimeout(updateVisual, 200);
|
||||
});
|
||||
updateVisual();
|
||||
|
||||
function updateVisual() {
|
||||
var out = document.getElementById("output");
|
||||
out.innerHTML = "";
|
||||
|
||||
function drawTree(out, node) {
|
||||
if (node.lines) {
|
||||
out.appendChild(document.createElement("div")).innerHTML =
|
||||
"<b>leaf</b>: " + node.lines.length + " lines, " + Math.round(node.height) + " px";
|
||||
var lines = out.appendChild(document.createElement("div"));
|
||||
lines.style.lineHeight = "6px"; lines.style.marginLeft = "10px";
|
||||
for (var i = 0; i < node.lines.length; ++i) {
|
||||
var line = node.lines[i], lineElt = lines.appendChild(document.createElement("div"));
|
||||
lineElt.className = "lineblock";
|
||||
var gray = Math.min(line.text.length * 3, 230), col = gray.toString(16);
|
||||
if (col.length == 1) col = "0" + col;
|
||||
lineElt.style.background = "#" + col + col + col;
|
||||
console.log(line.height, line);
|
||||
lineElt.style.width = Math.max(Math.round(line.height / 3), 1) + "px";
|
||||
}
|
||||
} else {
|
||||
out.appendChild(document.createElement("div")).innerHTML =
|
||||
"<b>node</b>: " + node.size + " lines, " + Math.round(node.height) + " px";
|
||||
var sub = out.appendChild(document.createElement("div"));
|
||||
sub.style.paddingLeft = "20px";
|
||||
for (var i = 0; i < node.children.length; ++i)
|
||||
drawTree(sub, node.children[i]);
|
||||
}
|
||||
}
|
||||
drawTree(out, editor.getDoc());
|
||||
}
|
||||
|
||||
function fillEditor() {
|
||||
var sc = document.getElementById("me");
|
||||
var doc = (sc.textContent || sc.innerText || sc.innerHTML).replace(/^\s*/, "") + "\n";
|
||||
doc += doc; doc += doc; doc += doc; doc += doc; doc += doc; doc += doc;
|
||||
editor.setValue(doc);
|
||||
}
|
||||
</script>
|
||||
|
||||
<p><button onclick="fillEditor()">Add a lot of content</button></p>
|
||||
|
||||
</article>
|
109
plugins/codemirror/codemirror/demo/buffers.html
vendored
Normal file
109
plugins/codemirror/codemirror/demo/buffers.html
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Multiple Buffer & Split View Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<style type="text/css" id=style>
|
||||
.CodeMirror {border: 1px solid black; height: 250px;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Multiple Buffer & Split View</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Multiple Buffer & Split View Demo</h2>
|
||||
|
||||
|
||||
<div id=code_top></div>
|
||||
<div>
|
||||
Select buffer: <select id=buffers_top></select>
|
||||
<button onclick="newBuf('top')">New buffer</button>
|
||||
</div>
|
||||
<div id=code_bot></div>
|
||||
<div>
|
||||
Select buffer: <select id=buffers_bot></select>
|
||||
<button onclick="newBuf('bot')">New buffer</button>
|
||||
</div>
|
||||
|
||||
<script id=script>
|
||||
var sel_top = document.getElementById("buffers_top");
|
||||
CodeMirror.on(sel_top, "change", function() {
|
||||
selectBuffer(ed_top, sel_top.options[sel_top.selectedIndex].value);
|
||||
});
|
||||
|
||||
var sel_bot = document.getElementById("buffers_bot");
|
||||
CodeMirror.on(sel_bot, "change", function() {
|
||||
selectBuffer(ed_bot, sel_bot.options[sel_bot.selectedIndex].value);
|
||||
});
|
||||
|
||||
var buffers = {};
|
||||
|
||||
function openBuffer(name, text, mode) {
|
||||
buffers[name] = CodeMirror.Doc(text, mode);
|
||||
var opt = document.createElement("option");
|
||||
opt.appendChild(document.createTextNode(name));
|
||||
sel_top.appendChild(opt);
|
||||
sel_bot.appendChild(opt.cloneNode(true));
|
||||
}
|
||||
|
||||
function newBuf(where) {
|
||||
var name = prompt("Name for the buffer", "*scratch*");
|
||||
if (name == null) return;
|
||||
if (buffers.hasOwnProperty(name)) {
|
||||
alert("There's already a buffer by that name.");
|
||||
return;
|
||||
}
|
||||
openBuffer(name, "", "javascript");
|
||||
selectBuffer(where == "top" ? ed_top : ed_bot, name);
|
||||
var sel = where == "top" ? sel_top : sel_bot;
|
||||
sel.value = name;
|
||||
}
|
||||
|
||||
function selectBuffer(editor, name) {
|
||||
var buf = buffers[name];
|
||||
if (buf.getEditor()) buf = buf.linkedDoc({sharedHist: true});
|
||||
var old = editor.swapDoc(buf);
|
||||
var linked = old.iterLinkedDocs(function(doc) {linked = doc;});
|
||||
if (linked) {
|
||||
// Make sure the document in buffers is the one the other view is looking at
|
||||
for (var name in buffers) if (buffers[name] == old) buffers[name] = linked;
|
||||
old.unlinkDoc(linked);
|
||||
}
|
||||
editor.focus();
|
||||
}
|
||||
|
||||
function nodeContent(id) {
|
||||
var node = document.getElementById(id), val = node.textContent || node.innerText;
|
||||
val = val.slice(val.match(/^\s*/)[0].length, val.length - val.match(/\s*$/)[0].length) + "\n";
|
||||
return val;
|
||||
}
|
||||
openBuffer("js", nodeContent("script"), "javascript");
|
||||
openBuffer("css", nodeContent("style"), "css");
|
||||
|
||||
var ed_top = CodeMirror(document.getElementById("code_top"), {lineNumbers: true});
|
||||
selectBuffer(ed_top, "js");
|
||||
var ed_bot = CodeMirror(document.getElementById("code_bot"), {lineNumbers: true});
|
||||
selectBuffer(ed_bot, "js");
|
||||
</script>
|
||||
|
||||
<p>Demonstration of
|
||||
using <a href="../doc/manual.html#linkedDoc">linked documents</a>
|
||||
to provide a split view on a document, and
|
||||
using <a href="../doc/manual.html#swapDoc"><code>swapDoc</code></a>
|
||||
to use a single editor to display multiple documents.</p>
|
||||
|
||||
</article>
|
59
plugins/codemirror/codemirror/demo/changemode.html
vendored
Normal file
59
plugins/codemirror/codemirror/demo/changemode.html
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Mode-Changing Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/scheme/scheme.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Mode-Changing</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Mode-Changing Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
;; If there is Scheme code in here, the editor will be in Scheme mode.
|
||||
;; If you put in JS instead, it'll switch to JS mode.
|
||||
|
||||
(define (double x)
|
||||
(* x x))
|
||||
</textarea></form>
|
||||
|
||||
<p>On changes to the content of the above editor, a (crude) script
|
||||
tries to auto-detect the language used, and switches the editor to
|
||||
either JavaScript or Scheme mode based on that.</p>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "scheme",
|
||||
lineNumbers: true,
|
||||
tabMode: "indent"
|
||||
});
|
||||
editor.on("change", function() {
|
||||
clearTimeout(pending);
|
||||
setTimeout(update, 400);
|
||||
});
|
||||
var pending;
|
||||
function looksLikeScheme(code) {
|
||||
return !/^\s*\(\s*function\b/.test(code) && /^\s*[;\(]/.test(code);
|
||||
}
|
||||
function update() {
|
||||
editor.setOption("mode", looksLikeScheme(editor.getValue()) ? "scheme" : "javascript");
|
||||
}
|
||||
</script>
|
||||
</article>
|
63
plugins/codemirror/codemirror/demo/closebrackets.html
vendored
Normal file
63
plugins/codemirror/codemirror/demo/closebrackets.html
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Closebrackets Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/edit/closebrackets.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Closebrackets</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Closebrackets Demo</h2>
|
||||
<form><textarea id="code" name="code">(function() {
|
||||
var DEFAULT_BRACKETS = "()[]{}''\"\"";
|
||||
|
||||
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
||||
var wasOn = old && old != CodeMirror.Init;
|
||||
if (val && !wasOn)
|
||||
cm.addKeyMap(buildKeymap(typeof val == "string" ? val : DEFAULT_BRACKETS));
|
||||
else if (!val && wasOn)
|
||||
cm.removeKeyMap("autoCloseBrackets");
|
||||
});
|
||||
|
||||
function buildKeymap(pairs) {
|
||||
var map = {name : "autoCloseBrackets"};
|
||||
for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
|
||||
function maybeOverwrite(cm) {
|
||||
var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
|
||||
if (ahead != right) return CodeMirror.Pass;
|
||||
else cm.execCommand("goCharRight");
|
||||
}
|
||||
map["'" + left + "'"] = function(cm) {
|
||||
if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
|
||||
var cur = cm.getCursor(), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
|
||||
cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
|
||||
};
|
||||
if (left != right) map["'" + right + "'"] = maybeOverwrite;
|
||||
})(pairs.charAt(i), pairs.charAt(i + 1));
|
||||
return map;
|
||||
}
|
||||
})();
|
||||
</textarea></form>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {autoCloseBrackets: true});
|
||||
</script>
|
||||
</article>
|
40
plugins/codemirror/codemirror/demo/closetag.html
vendored
Normal file
40
plugins/codemirror/codemirror/demo/closetag.html
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Close-Tag Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/edit/closetag.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<script src="../mode/htmlmixed/htmlmixed.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Close-Tag</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Close-Tag Demo</h2>
|
||||
<form><textarea id="code" name="code"><html</textarea></form>
|
||||
|
||||
<script type="text/javascript">
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: 'text/html',
|
||||
autoCloseTags: true
|
||||
});
|
||||
</script>
|
||||
</article>
|
80
plugins/codemirror/codemirror/demo/complete.html
vendored
Normal file
80
plugins/codemirror/codemirror/demo/complete.html
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Autocomplete Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/hint/show-hint.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/hint/show-hint.js"></script>
|
||||
<script src="../addon/hint/javascript-hint.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Autocomplete</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Autocomplete Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
function getCompletions(token, context) {
|
||||
var found = [], start = token.string;
|
||||
function maybeAdd(str) {
|
||||
if (str.indexOf(start) == 0) found.push(str);
|
||||
}
|
||||
function gatherCompletions(obj) {
|
||||
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
||||
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
||||
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
||||
for (var name in obj) maybeAdd(name);
|
||||
}
|
||||
|
||||
if (context) {
|
||||
// If this is a property, see if it belongs to some object we can
|
||||
// find in the current environment.
|
||||
var obj = context.pop(), base;
|
||||
if (obj.className == "js-variable")
|
||||
base = window[obj.string];
|
||||
else if (obj.className == "js-string")
|
||||
base = "";
|
||||
else if (obj.className == "js-atom")
|
||||
base = 1;
|
||||
while (base != null && context.length)
|
||||
base = base[context.pop().string];
|
||||
if (base != null) gatherCompletions(base);
|
||||
}
|
||||
else {
|
||||
// If not, just look in the window object and any local scope
|
||||
// (reading into JS mode internals to get at the local variables)
|
||||
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
||||
gatherCompletions(window);
|
||||
forEach(keywords, maybeAdd);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<p>Press <strong>ctrl-space</strong> to activate autocompletion. Built
|
||||
on top of the <a href="../doc/manual.html#addon_show-hint"><code>show-hint</code></a>
|
||||
and <a href="../doc/manual.html#addon_javascript-hint"><code>javascript-hint</code></a>
|
||||
addons.</p>
|
||||
|
||||
<script>
|
||||
CodeMirror.commands.autocomplete = function(cm) {
|
||||
CodeMirror.showHint(cm, CodeMirror.hint.javascript);
|
||||
};
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"}
|
||||
});
|
||||
</script>
|
||||
</article>
|
75
plugins/codemirror/codemirror/demo/emacs.html
vendored
Normal file
75
plugins/codemirror/codemirror/demo/emacs.html
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Emacs bindings demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/dialog/dialog.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/clike/clike.js"></script>
|
||||
<script src="../keymap/emacs.js"></script>
|
||||
<script src="../addon/edit/matchbrackets.js"></script>
|
||||
<script src="../addon/comment/comment.js"></script>
|
||||
<script src="../addon/dialog/dialog.js"></script>
|
||||
<script src="../addon/search/searchcursor.js"></script>
|
||||
<script src="../addon/search/search.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Emacs bindings</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Emacs bindings demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
#include "syscalls.h"
|
||||
/* getchar: simple buffered version */
|
||||
int getchar(void)
|
||||
{
|
||||
static char buf[BUFSIZ];
|
||||
static char *bufp = buf;
|
||||
static int n = 0;
|
||||
if (n == 0) { /* buffer is empty */
|
||||
n = read(0, buf, sizeof buf);
|
||||
bufp = buf;
|
||||
}
|
||||
return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<p>The emacs keybindings are enabled by
|
||||
including <a href="../keymap/emacs.js">keymap/emacs.js</a> and setting
|
||||
the <code>keyMap</code> option to <code>"emacs"</code>. Because
|
||||
CodeMirror's internal API is quite different from Emacs, they are only
|
||||
a loose approximation of actual emacs bindings, though.</p>
|
||||
|
||||
<p>Also note that a lot of browsers disallow certain keys from being
|
||||
captured. For example, Chrome blocks both Ctrl-W and Ctrl-N, with the
|
||||
result that idiomatic use of Emacs keys will constantly close your tab
|
||||
or open a new window.</p>
|
||||
|
||||
<script>
|
||||
CodeMirror.commands.save = function() {
|
||||
var elt = editor.getWrapperElement();
|
||||
elt.style.background = "#def";
|
||||
setTimeout(function() { elt.style.background = ""; }, 300);
|
||||
};
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
mode: "text/x-csrc",
|
||||
keyMap: "emacs"
|
||||
});
|
||||
</script>
|
||||
|
||||
</article>
|
75
plugins/codemirror/codemirror/demo/folding.html
vendored
Normal file
75
plugins/codemirror/codemirror/demo/folding.html
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Code Folding Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/fold/foldgutter.css" />
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/fold/foldcode.js"></script>
|
||||
<script src="../addon/fold/foldgutter.js"></script>
|
||||
<script src="../addon/fold/brace-fold.js"></script>
|
||||
<script src="../addon/fold/xml-fold.js"></script>
|
||||
<script src="../addon/fold/comment-fold.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Code Folding</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Code Folding Demo</h2>
|
||||
<form>
|
||||
<div style="max-width: 50em; margin-bottom: 1em">JavaScript:<br><textarea id="code" name="code"></textarea></div>
|
||||
<div style="max-width: 50em">HTML:<br><textarea id="code-html" name="code-html"></textarea></div>
|
||||
</form>
|
||||
<script id="script">
|
||||
/*
|
||||
* Demonstration of code folding
|
||||
*/
|
||||
window.onload = function() {
|
||||
var te = document.getElementById("code");
|
||||
var sc = document.getElementById("script");
|
||||
te.value = (sc.textContent || sc.innerText || sc.innerHTML).replace(/^\s*/, "");
|
||||
sc.innerHTML = "";
|
||||
var te_html = document.getElementById("code-html");
|
||||
te_html.value = "<html>\n " + document.documentElement.innerHTML + "\n</html>";
|
||||
|
||||
window.editor = CodeMirror.fromTextArea(te, {
|
||||
mode: "javascript",
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
|
||||
foldGutter: {
|
||||
rangeFinder: new CodeMirror.fold.combine(CodeMirror.fold.brace, CodeMirror.fold.comment)
|
||||
},
|
||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
|
||||
});
|
||||
editor.foldCode(CodeMirror.Pos(8, 0));
|
||||
|
||||
window.editor_html = CodeMirror.fromTextArea(te_html, {
|
||||
mode: "text/html",
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
|
||||
foldGutter: true,
|
||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
|
||||
});
|
||||
editor_html.foldCode(CodeMirror.Pos(13, 0));
|
||||
editor_html.foldCode(CodeMirror.Pos(1, 0));
|
||||
};
|
||||
</script>
|
||||
</article>
|
130
plugins/codemirror/codemirror/demo/fullscreen.html
vendored
Normal file
130
plugins/codemirror/codemirror/demo/fullscreen.html
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Full Screen Editing</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/display/fullscreen.css">
|
||||
<link rel="stylesheet" href="../theme/night.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../addon/display/fullscreen.js"></script>
|
||||
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Full Screen Editing</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Full Screen Editing</h2>
|
||||
<form><textarea id="code" name="code" rows="5">
|
||||
<dt id="option_indentWithTabs"><code>indentWithTabs (boolean)</code></dt>
|
||||
<dd>Whether, when indenting, the first N*8 spaces should be
|
||||
replaced by N tabs. Default is false.</dd>
|
||||
|
||||
<dt id="option_tabMode"><code>tabMode (string)</code></dt>
|
||||
<dd>Determines what happens when the user presses the tab key.
|
||||
Must be one of the following:
|
||||
<dl>
|
||||
<dt><code>"classic" (the default)</code></dt>
|
||||
<dd>When nothing is selected, insert a tab. Otherwise,
|
||||
behave like the <code>"shift"</code> mode. (When shift is
|
||||
held, this behaves like the <code>"indent"</code> mode.)</dd>
|
||||
<dt><code>"shift"</code></dt>
|
||||
<dd>Indent all selected lines by
|
||||
one <a href="#option_indentUnit"><code>indentUnit</code></a>.
|
||||
If shift was held while pressing tab, un-indent all selected
|
||||
lines one unit.</dd>
|
||||
<dt><code>"indent"</code></dt>
|
||||
<dd>Indent the line the 'correctly', based on its syntactic
|
||||
context. Only works if the
|
||||
mode <a href="#indent">supports</a> it.</dd>
|
||||
<dt><code>"default"</code></dt>
|
||||
<dd>Do not capture tab presses, let the browser apply its
|
||||
default behaviour (which usually means it skips to the next
|
||||
control).</dd>
|
||||
</dl></dd>
|
||||
|
||||
<dt id="option_enterMode"><code>enterMode (string)</code></dt>
|
||||
<dd>Determines whether and how new lines are indented when the
|
||||
enter key is pressed. The following modes are supported:
|
||||
<dl>
|
||||
<dt><code>"indent" (the default)</code></dt>
|
||||
<dd>Use the mode's indentation rules to give the new line
|
||||
the correct indentation.</dd>
|
||||
<dt><code>"keep"</code></dt>
|
||||
<dd>Indent the line the same as the previous line.</dd>
|
||||
<dt><code>"flat"</code></dt>
|
||||
<dd>Do not indent the new line.</dd>
|
||||
</dl></dd>
|
||||
|
||||
<dt id="option_enterMode"><code>enterMode (string)</code></dt>
|
||||
<dd>Determines whether and how new lines are indented when the
|
||||
enter key is pressed. The following modes are supported:
|
||||
<dl>
|
||||
<dt><code>"indent" (the default)</code></dt>
|
||||
<dd>Use the mode's indentation rules to give the new line
|
||||
the correct indentation.</dd>
|
||||
<dt><code>"keep"</code></dt>
|
||||
<dd>Indent the line the same as the previous line.</dd>
|
||||
<dt><code>"flat"</code></dt>
|
||||
<dd>Do not indent the new line.</dd>
|
||||
</dl></dd>
|
||||
|
||||
<dt id="option_enterMode"><code>enterMode (string)</code></dt>
|
||||
<dd>Determines whether and how new lines are indented when the
|
||||
enter key is pressed. The following modes are supported:
|
||||
<dl>
|
||||
<dt><code>"indent" (the default)</code></dt>
|
||||
<dd>Use the mode's indentation rules to give the new line
|
||||
the correct indentation.</dd>
|
||||
<dt><code>"keep"</code></dt>
|
||||
<dd>Indent the line the same as the previous line.</dd>
|
||||
<dt><code>"flat"</code></dt>
|
||||
<dd>Do not indent the new line.</dd>
|
||||
</dl></dd>
|
||||
|
||||
<dt id="option_enterMode"><code>enterMode (string)</code></dt>
|
||||
<dd>Determines whether and how new lines are indented when the
|
||||
enter key is pressed. The following modes are supported:
|
||||
<dl>
|
||||
<dt><code>"indent" (the default)</code></dt>
|
||||
<dd>Use the mode's indentation rules to give the new line
|
||||
the correct indentation.</dd>
|
||||
<dt><code>"keep"</code></dt>
|
||||
<dd>Indent the line the same as the previous line.</dd>
|
||||
<dt><code>"flat"</code></dt>
|
||||
<dd>Do not indent the new line.</dd>
|
||||
</dl></dd>
|
||||
|
||||
</textarea></form>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
theme: "night",
|
||||
extraKeys: {
|
||||
"F11": function(cm) {
|
||||
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
|
||||
},
|
||||
"Esc": function(cm) {
|
||||
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Demonstration of
|
||||
the <a href="../doc/manual.html#addon_fullscreen">fullscreen</a>
|
||||
addon. Press <strong>F11</strong> when cursor is in the editor to
|
||||
toggle full screen editing. <strong>Esc</strong> can also be used
|
||||
to <i>exit</i> full screen editing.</p>
|
||||
</article>
|
69
plugins/codemirror/codemirror/demo/hardwrap.html
vendored
Normal file
69
plugins/codemirror/codemirror/demo/hardwrap.html
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Hard-wrapping Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/markdown/markdown.js"></script>
|
||||
<script src="../addon/wrap/hardwrap.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Hard-wrapping</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Hard-wrapping Demo</h2>
|
||||
<form><textarea id="code" name="code">Lorem ipsum dolor sit amet, vim augue dictas constituto ex,
|
||||
sit falli simul viderer te. Graeco scaevola maluisset sit
|
||||
ut, in idque viris praesent sea. Ea sea eirmod indoctum
|
||||
repudiare. Vel noluisse suscipit pericula ut. In ius nulla
|
||||
alienum molestie. Mei essent discere democritum id.
|
||||
|
||||
Equidem ponderum expetendis ius in, mea an erroribus
|
||||
constituto, congue timeam perfecto ad est. Ius ut primis
|
||||
timeam, per in ullum mediocrem. An case vero labitur pri,
|
||||
vel dicit laoreet et. An qui prompta conclusionemque, eam
|
||||
timeam sapientem in, cum dictas epicurei eu.
|
||||
|
||||
Usu cu vide dictas deseruisse, eum choro graece adipiscing
|
||||
ut. Cibo qualisque ius ad, et dicat scripta mea, eam nihil
|
||||
mentitum aliquando cu. Debet aperiam splendide at quo, ad
|
||||
paulo nostro commodo duo. Sea adhuc utinam conclusionemque
|
||||
id, quas doming malorum nec ad. Tollit eruditi vivendum ad
|
||||
ius, eos soleat ignota ad.
|
||||
</textarea></form>
|
||||
|
||||
<p>Demonstration of
|
||||
the <a href="../doc/manual.html#addon_hardwrap">hardwrap</a> addon.
|
||||
The above editor has its change event hooked up to
|
||||
the <code>wrapParagraphsInRange</code> method, so that the paragraphs
|
||||
are reflown as you are typing.</p>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "markdown",
|
||||
lineNumbers: true
|
||||
});
|
||||
var wait, options = {column: 60};
|
||||
editor.on("change", function(cm, change) {
|
||||
clearTimeout(wait);
|
||||
wait = setTimeout(function() {
|
||||
cm.wrapParagraphsInRange(change.from, CodeMirror.changeEnd(change), options);
|
||||
}, 200);
|
||||
});
|
||||
</script>
|
||||
|
||||
</article>
|
54
plugins/codemirror/codemirror/demo/html5complete.html
vendored
Normal file
54
plugins/codemirror/codemirror/demo/html5complete.html
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: HTML completion demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/hint/show-hint.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/hint/show-hint.js"></script>
|
||||
<script src="../addon/hint/xml-hint.js"></script>
|
||||
<script src="../addon/hint/html-hint.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<script src="../mode/htmlmixed/htmlmixed.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">HTML completion</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>HTML completion demo</h2>
|
||||
|
||||
<p>Shows the <a href="xmlcomplete.html">XML completer</a>
|
||||
parameterized with information about the tags in HTML.
|
||||
Press <strong>ctrl-space</strong> to activate completion.</p>
|
||||
|
||||
<div id="code"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
CodeMirror.commands.autocomplete = function(cm) {
|
||||
CodeMirror.showHint(cm, CodeMirror.hint.html);
|
||||
}
|
||||
window.onload = function() {
|
||||
editor = CodeMirror(document.getElementById("code"), {
|
||||
mode: "text/html",
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
value: "<!doctype html>\n<html>\n " + document.documentElement.innerHTML + "\n</html>"
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</article>
|
58
plugins/codemirror/codemirror/demo/indentwrap.html
vendored
Normal file
58
plugins/codemirror/codemirror/demo/indentwrap.html
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Indented wrapped line demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Indented wrapped line</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Indented wrapped line demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
<!doctype html>
|
||||
<body>
|
||||
<h2 id="overview">Overview</h2>
|
||||
|
||||
<p>CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides <em>only</em> the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does provide a rich API on top of which such functionality can be straightforwardly implemented. See the <a href="#addons">add-ons</a> included in the distribution, and the <a href="https://github.com/jagthedrummer/codemirror-ui">CodeMirror UI</a> project, for reusable implementations of extra features.</p>
|
||||
|
||||
<p>CodeMirror works with language-specific modes. Modes are JavaScript programs that help color (and optionally indent) text written in a given language. The distribution comes with a number of modes (see the <a href="../mode/"><code>mode/</code></a> directory), and it isn't hard to <a href="#modeapi">write new ones</a> for other languages.</p>
|
||||
</body>
|
||||
</textarea></form>
|
||||
|
||||
<p>This page uses a hack on top of the <code>"renderLine"</code>
|
||||
event to make wrapped text line up with the base indentation of
|
||||
the line.</p>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
mode: "text/html"
|
||||
});
|
||||
var charWidth = editor.defaultCharWidth(), basePadding = 4;
|
||||
editor.on("renderLine", function(cm, line, elt) {
|
||||
var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;
|
||||
elt.style.textIndent = "-" + off + "px";
|
||||
elt.style.paddingLeft = (basePadding + off) + "px";
|
||||
});
|
||||
editor.refresh();
|
||||
</script>
|
||||
|
||||
</article>
|
171
plugins/codemirror/codemirror/demo/lint.html
vendored
Normal file
171
plugins/codemirror/codemirror/demo/lint.html
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Linter Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<link rel="stylesheet" href="../addon/lint/lint.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<script src="http://ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js"></script>
|
||||
<script src="https://rawgithub.com/zaach/jsonlint/79b553fb65c192add9066da64043458981b3972b/lib/jsonlint.js"></script>
|
||||
<script src="https://rawgithub.com/stubbornella/csslint/master/release/csslint.js"></script>
|
||||
<script src="../addon/lint/lint.js"></script>
|
||||
<script src="../addon/lint/javascript-lint.js"></script>
|
||||
<script src="../addon/lint/json-lint.js"></script>
|
||||
<script src="../addon/lint/css-lint.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Linter</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Linter Demo</h2>
|
||||
|
||||
|
||||
<p><textarea id="code-js">var widgets = []
|
||||
function updateHints() {
|
||||
editor.operation(function(){
|
||||
for (var i = 0; i < widgets.length; ++i)
|
||||
editor.removeLineWidget(widgets[i]);
|
||||
widgets.length = 0;
|
||||
|
||||
JSHINT(editor.getValue());
|
||||
for (var i = 0; i < JSHINT.errors.length; ++i) {
|
||||
var err = JSHINT.errors[i];
|
||||
if (!err) continue;
|
||||
var msg = document.createElement("div");
|
||||
var icon = msg.appendChild(document.createElement("span"));
|
||||
icon.innerHTML = "!!";
|
||||
icon.className = "lint-error-icon";
|
||||
msg.appendChild(document.createTextNode(err.reason));
|
||||
msg.className = "lint-error";
|
||||
widgets.push(editor.addLineWidget(err.line - 1, msg, {coverGutter: false, noHScroll: true}));
|
||||
}
|
||||
});
|
||||
var info = editor.getScrollInfo();
|
||||
var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
|
||||
if (info.top + info.clientHeight < after)
|
||||
editor.scrollTo(null, after - info.clientHeight + 3);
|
||||
}
|
||||
</textarea></p>
|
||||
|
||||
<p><textarea id="code-json">[
|
||||
{
|
||||
_id: "post 1",
|
||||
"author": "Bob",
|
||||
"content": "...",
|
||||
"page_views": 5
|
||||
},
|
||||
{
|
||||
"_id": "post 2",
|
||||
"author": "Bob",
|
||||
"content": "...",
|
||||
"page_views": 9
|
||||
},
|
||||
{
|
||||
"_id": "post 3",
|
||||
"author": "Bob",
|
||||
"content": "...",
|
||||
"page_views": 8
|
||||
}
|
||||
]
|
||||
</textarea></p>
|
||||
|
||||
<p><textarea id="code-css">@charset "UTF-8";
|
||||
|
||||
@import url("booya.css") print, screen;
|
||||
@import "whatup.css" screen;
|
||||
@import "wicked.css";
|
||||
|
||||
/*Error*/
|
||||
@charset "UTF-8";
|
||||
|
||||
|
||||
@namespace "http://www.w3.org/1999/xhtml";
|
||||
@namespace svg "http://www.w3.org/2000/svg";
|
||||
|
||||
/*Warning: empty ruleset */
|
||||
.foo {
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/*Warning: qualified heading */
|
||||
.foo h1 {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/*Warning: adjoining classes */
|
||||
.foo.bar {
|
||||
zoom: 1;
|
||||
}
|
||||
|
||||
li.inline {
|
||||
width: 100%; /*Warning: 100% can be problematic*/
|
||||
}
|
||||
|
||||
li.last {
|
||||
display: inline;
|
||||
padding-left: 3px !important;
|
||||
padding-right: 3px;
|
||||
border-right: 0px;
|
||||
}
|
||||
|
||||
@media print {
|
||||
li.inline {
|
||||
color: black;
|
||||
}
|
||||
}
|
||||
|
||||
@page {
|
||||
margin: 10%;
|
||||
counter-increment: page;
|
||||
|
||||
@top-center {
|
||||
font-family: sans-serif;
|
||||
font-weight: bold;
|
||||
font-size: 2em;
|
||||
content: counter(page);
|
||||
}
|
||||
}
|
||||
</textarea></p>
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code-js"), {
|
||||
lineNumbers: true,
|
||||
mode: "javascript",
|
||||
gutters: ["CodeMirror-lint-markers"],
|
||||
lint: true
|
||||
});
|
||||
|
||||
var editor_json = CodeMirror.fromTextArea(document.getElementById("code-json"), {
|
||||
lineNumbers: true,
|
||||
mode: "application/json",
|
||||
gutters: ["CodeMirror-lint-markers"],
|
||||
lint: true
|
||||
});
|
||||
|
||||
var editor_css = CodeMirror.fromTextArea(document.getElementById("code-css"), {
|
||||
lineNumbers: true,
|
||||
mode: "css",
|
||||
gutters: ["CodeMirror-lint-markers"],
|
||||
lint: true
|
||||
});
|
||||
</script>
|
||||
|
||||
</article>
|
49
plugins/codemirror/codemirror/demo/loadmode.html
vendored
Normal file
49
plugins/codemirror/codemirror/demo/loadmode.html
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Lazy Mode Loading Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/mode/loadmode.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Lazy Mode Loading</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Lazy Mode Loading Demo</h2>
|
||||
<form><textarea id="code" name="code">This is the editor.
|
||||
// It starts out in plain text mode,
|
||||
# use the control below to load and apply a mode
|
||||
"you'll see the highlighting of" this text /*change*/.
|
||||
</textarea></form>
|
||||
<p><input type=text value=javascript id=mode> <button type=button onclick="change()">change mode</button></p>
|
||||
|
||||
<script>
|
||||
CodeMirror.modeURL = "../mode/%N/%N.js";
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true
|
||||
});
|
||||
var modeInput = document.getElementById("mode");
|
||||
CodeMirror.on(modeInput, "keypress", function(e) {
|
||||
if (e.keyCode == 13) change();
|
||||
});
|
||||
function change() {
|
||||
editor.setOption("mode", modeInput.value);
|
||||
CodeMirror.autoLoadMode(editor, modeInput.value);
|
||||
}
|
||||
</script>
|
||||
</article>
|
52
plugins/codemirror/codemirror/demo/marker.html
vendored
Normal file
52
plugins/codemirror/codemirror/demo/marker.html
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Breakpoint Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<style type="text/css">
|
||||
.breakpoints {width: .8em;}
|
||||
.breakpoint { color: #822; }
|
||||
.CodeMirror {border: 1px solid #aaa;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Breakpoint</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Breakpoint Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
gutters: ["CodeMirror-linenumbers", "breakpoints"]
|
||||
});
|
||||
editor.on("gutterClick", function(cm, n) {
|
||||
var info = cm.lineInfo(n);
|
||||
cm.setGutterMarker(n, "breakpoints", info.gutterMarkers ? null : makeMarker());
|
||||
});
|
||||
|
||||
function makeMarker() {
|
||||
var marker = document.createElement("div");
|
||||
marker.style.color = "#822";
|
||||
marker.innerHTML = "●";
|
||||
return marker;
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<p>Click the line-number gutter to add or remove 'breakpoints'.</p>
|
||||
|
||||
<script>eval(document.getElementById("code").value);</script>
|
||||
|
||||
</article>
|
45
plugins/codemirror/codemirror/demo/markselection.html
vendored
Normal file
45
plugins/codemirror/codemirror/demo/markselection.html
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Match Selection Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/search/searchcursor.js"></script>
|
||||
<script src="../addon/selection/mark-selection.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
.CodeMirror-selected { background-color: blue !important; }
|
||||
.CodeMirror-selectedtext { color: white; }
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Match Selection</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Match Selection Demo</h2>
|
||||
<form><textarea id="code" name="code">Select something from here.
|
||||
You'll see that the selection's foreground color changes to white!
|
||||
Since, by default, CodeMirror only puts an independent "marker" layer
|
||||
behind the text, you'll need something like this to change its colour.</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
styleSelectedText: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Simple addon to easily mark (and style) selected text.</p>
|
||||
|
||||
</article>
|
47
plugins/codemirror/codemirror/demo/matchhighlighter.html
vendored
Normal file
47
plugins/codemirror/codemirror/demo/matchhighlighter.html
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Match Highlighter Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/search/searchcursor.js"></script>
|
||||
<script src="../addon/search/match-highlighter.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
.CodeMirror-focused .cm-matchhighlight {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==);
|
||||
background-position: bottom;
|
||||
background-repeat: repeat-x;
|
||||
}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Match Highlighter</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Match Highlighter Demo</h2>
|
||||
<form><textarea id="code" name="code">Select this text: hardToSpotVar
|
||||
And everywhere else in your code where hardToSpotVar appears will automatically illuminate.
|
||||
Give it a try! No more hardToSpotVars.</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
highlightSelectionMatches: {showToken: /\w/}
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Search and highlight occurences of the selected text.</p>
|
||||
|
||||
</article>
|
49
plugins/codemirror/codemirror/demo/matchtags.html
vendored
Normal file
49
plugins/codemirror/codemirror/demo/matchtags.html
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Tag Matcher Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/fold/xml-fold.js"></script>
|
||||
<script src="../addon/edit/matchtags.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Tag Matcher</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Tag Matcher Demo</h2>
|
||||
|
||||
|
||||
<div id="editor"></div>
|
||||
|
||||
<script>
|
||||
window.onload = function() {
|
||||
editor = CodeMirror(document.getElementById("editor"), {
|
||||
value: "<html>\n " + document.documentElement.innerHTML + "\n</html>",
|
||||
mode: "text/html",
|
||||
matchTags: {bothTags: true},
|
||||
extraKeys: {"Ctrl-J": "toMatchingTag"}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<p>Put the cursor on or inside a pair of tags to highlight them.
|
||||
Press Ctrl-J to jump to the tag that matches the one under the
|
||||
cursor.</p>
|
||||
</article>
|
82
plugins/codemirror/codemirror/demo/merge.html
vendored
Normal file
82
plugins/codemirror/codemirror/demo/merge.html
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: merge view demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel=stylesheet href="../lib/codemirror.css">
|
||||
<link rel=stylesheet href="../addon/merge/merge.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<script src="../addon/merge/dep/diff_match_patch.js"></script>
|
||||
<script src="../addon/merge/merge.js"></script>
|
||||
<style>
|
||||
.CodeMirror { line-height: 1.2; }
|
||||
body { max-width: 80em; }
|
||||
span.clicky {
|
||||
cursor: pointer;
|
||||
background: #d70;
|
||||
color: white;
|
||||
padding: 0 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">merge view</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>merge view demo</h2>
|
||||
|
||||
|
||||
<div id=view></div>
|
||||
|
||||
<p>The <a href="../doc/manual.html#addon_merge"><code>merge</code></a>
|
||||
addon provides an interface for displaying and merging diffs,
|
||||
either <span class=clicky onclick="initUI(2)">two-way</span>
|
||||
or <span class=clicky onclick="initUI(3)">three-way</span>. The left
|
||||
(or center) pane is editable, and the differences with the other
|
||||
pane(s) are <span class=clicky onclick="toggleDifferences()">optionally</span> shown live as you edit it.</p>
|
||||
|
||||
<p>This addon depends on
|
||||
the <a href="https://code.google.com/p/google-diff-match-patch/">google-diff-match-patch</a>
|
||||
library to compute the diffs.</p>
|
||||
|
||||
<script>
|
||||
var value, orig1, orig2, dv, hilight= true;
|
||||
function initUI(panes) {
|
||||
if (value == null) return;
|
||||
var target = document.getElementById("view");
|
||||
target.innerHTML = "";
|
||||
dv = CodeMirror.MergeView(target, {
|
||||
value: value,
|
||||
origLeft: panes == 3 ? orig1 : null,
|
||||
orig: orig2,
|
||||
lineNumbers: true,
|
||||
mode: "text/html",
|
||||
highlightDifferences: hilight
|
||||
});
|
||||
}
|
||||
|
||||
function toggleDifferences() {
|
||||
dv.setShowDifferences(hilight = !hilight);
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
value = document.documentElement.innerHTML;
|
||||
orig1 = value.replace(/\.\.\//g, "codemirror/").replace("yellow", "orange");
|
||||
orig2 = value.replace(/\u003cscript/g, "\u003cscript type=text/javascript ")
|
||||
.replace("white", "purple;\n font: comic sans;\n text-decoration: underline;\n height: 15em");
|
||||
initUI(2);
|
||||
};
|
||||
</script>
|
||||
</article>
|
75
plugins/codemirror/codemirror/demo/multiplex.html
vendored
Normal file
75
plugins/codemirror/codemirror/demo/multiplex.html
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Multiplexing Parser Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/mode/multiplex.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border: 1px solid black;}
|
||||
.cm-delimit {color: #fa4;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Multiplexing Parser</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Multiplexing Parser Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
<html>
|
||||
<body style="<<magic>>">
|
||||
<h1><< this is not <html >></h1>
|
||||
<<
|
||||
multiline
|
||||
not html
|
||||
at all : &amp; <link/>
|
||||
>>
|
||||
<p>this is html again</p>
|
||||
</body>
|
||||
</html>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
CodeMirror.defineMode("demo", function(config) {
|
||||
return CodeMirror.multiplexingMode(
|
||||
CodeMirror.getMode(config, "text/html"),
|
||||
{open: "<<", close: ">>",
|
||||
mode: CodeMirror.getMode(config, "text/plain"),
|
||||
delimStyle: "delimit"}
|
||||
// .. more multiplexed styles can follow here
|
||||
);
|
||||
});
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "demo",
|
||||
lineNumbers: true,
|
||||
lineWrapping: true
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>Demonstration of a multiplexing mode, which, at certain
|
||||
boundary strings, switches to one or more inner modes. The out
|
||||
(HTML) mode does not get fed the content of the <code><<
|
||||
>></code> blocks. See
|
||||
the <a href="../doc/manual.html#addon_multiplex">manual</a> and
|
||||
the <a href="../addon/mode/multiplex.js">source</a> for more
|
||||
information.</p>
|
||||
|
||||
<p>
|
||||
<strong>Parsing/Highlighting Tests:</strong>
|
||||
<a href="../test/index.html#multiplexing_*">normal</a>,
|
||||
<a href="../test/index.html#verbose,multiplexing_*">verbose</a>.
|
||||
</p>
|
||||
|
||||
</article>
|
68
plugins/codemirror/codemirror/demo/mustache.html
vendored
Normal file
68
plugins/codemirror/codemirror/demo/mustache.html
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Overlay Parser Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/mode/overlay.js"></script>
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {border: 1px solid black;}
|
||||
.cm-mustache {color: #0ca;}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Overlay Parser</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Overlay Parser Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
<html>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
<p>These are links to {{things}}:</p>
|
||||
<ul>{{#links}}
|
||||
<li><a href="{{url}}">{{text}}</a></li>
|
||||
{{/links}}</ul>
|
||||
</body>
|
||||
</html>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
CodeMirror.defineMode("mustache", function(config, parserConfig) {
|
||||
var mustacheOverlay = {
|
||||
token: function(stream, state) {
|
||||
var ch;
|
||||
if (stream.match("{{")) {
|
||||
while ((ch = stream.next()) != null)
|
||||
if (ch == "}" && stream.next() == "}") break;
|
||||
stream.eat("}");
|
||||
return "mustache";
|
||||
}
|
||||
while (stream.next() != null && !stream.match("{{", false)) {}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mustacheOverlay);
|
||||
});
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "mustache"});
|
||||
</script>
|
||||
|
||||
<p>Demonstration of a mode that parses HTML, highlighting
|
||||
the <a href="http://mustache.github.com/">Mustache</a> templating
|
||||
directives inside of it by using the code
|
||||
in <a href="../addon/mode/overlay.js"><code>overlay.js</code></a>. View
|
||||
source to see the 15 lines of code needed to accomplish this.</p>
|
||||
|
||||
</article>
|
45
plugins/codemirror/codemirror/demo/placeholder.html
vendored
Normal file
45
plugins/codemirror/codemirror/demo/placeholder.html
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Placeholder demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../addon/display/placeholder.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror { border: 1px solid silver; }
|
||||
.CodeMirror-empty { outline: 1px solid #c22; }
|
||||
.CodeMirror-empty.CodeMirror-focused { outline: none; }
|
||||
.CodeMirror pre.CodeMirror-placeholder { color: #999; }
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Placeholder</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Placeholder demo</h2>
|
||||
<form><textarea id="code" name="code" placeholder="Code goes here..."></textarea></form>
|
||||
|
||||
<p>The <a href="../doc/manual.html#addon_placeholder">placeholder</a>
|
||||
plug-in adds an option <code>placeholder</code> that can be set to
|
||||
make text appear in the editor when it is empty and not focused.
|
||||
If the source textarea has a <code>placeholder</code> attribute,
|
||||
it will automatically be inherited.</p>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true
|
||||
});
|
||||
</script>
|
||||
|
||||
</article>
|
88
plugins/codemirror/codemirror/demo/preview.html
vendored
Normal file
88
plugins/codemirror/codemirror/demo/preview.html
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: HTML5 preview</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel=stylesheet href=../lib/codemirror.css>
|
||||
<script src=../lib/codemirror.js></script>
|
||||
<script src=../mode/xml/xml.js></script>
|
||||
<script src=../mode/javascript/javascript.js></script>
|
||||
<script src=../mode/css/css.js></script>
|
||||
<script src=../mode/htmlmixed/htmlmixed.js></script>
|
||||
<style type=text/css>
|
||||
.CodeMirror {
|
||||
float: left;
|
||||
width: 50%;
|
||||
border: 1px solid black;
|
||||
}
|
||||
iframe {
|
||||
width: 49%;
|
||||
float: left;
|
||||
height: 300px;
|
||||
border: 1px solid black;
|
||||
border-left: 0px;
|
||||
}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">HTML5 preview</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>HTML5 preview</h2>
|
||||
|
||||
<textarea id=code name=code>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>HTML5 canvas demo</title>
|
||||
<style>p {font-family: monospace;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>Canvas pane goes here:</p>
|
||||
<canvas id=pane width=300 height=200></canvas>
|
||||
<script>
|
||||
var canvas = document.getElementById('pane');
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
context.fillStyle = 'rgb(250,0,0)';
|
||||
context.fillRect(10, 10, 55, 50);
|
||||
|
||||
context.fillStyle = 'rgba(0, 0, 250, 0.5)';
|
||||
context.fillRect(30, 30, 55, 50);
|
||||
</script>
|
||||
</body>
|
||||
</html></textarea>
|
||||
<iframe id=preview></iframe>
|
||||
<script>
|
||||
var delay;
|
||||
// Initialize CodeMirror editor with a nice html5 canvas demo.
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
|
||||
mode: 'text/html',
|
||||
tabMode: 'indent'
|
||||
});
|
||||
editor.on("change", function() {
|
||||
clearTimeout(delay);
|
||||
delay = setTimeout(updatePreview, 300);
|
||||
});
|
||||
|
||||
function updatePreview() {
|
||||
var previewFrame = document.getElementById('preview');
|
||||
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
|
||||
preview.open();
|
||||
preview.write(editor.getValue());
|
||||
preview.close();
|
||||
}
|
||||
setTimeout(updatePreview, 300);
|
||||
</script>
|
||||
</article>
|
58
plugins/codemirror/codemirror/demo/resize.html
vendored
Normal file
58
plugins/codemirror/codemirror/demo/resize.html
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Autoresize Demo</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
height: auto;
|
||||
}
|
||||
.CodeMirror-scroll {
|
||||
overflow-y: hidden;
|
||||
overflow-x: auto;
|
||||
}
|
||||
</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Home</a>
|
||||
<li><a href="../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/marijnh/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class=active href="#">Autoresize</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Autoresize Demo</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
.CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
height: auto;
|
||||
}
|
||||
.CodeMirror-scroll {
|
||||
overflow-y: hidden;
|
||||
overflow-x: auto;
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<p>By setting a few CSS properties, and giving
|
||||
the <a href="../doc/manual.html#option_viewportMargin"><code>viewportMargin</code></a>
|
||||
a value of <code>Infinity</code>, CodeMirror can be made to
|
||||
automatically resize to fit its content.</p>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
viewportMargin: Infinity
|
||||
});
|
||||
</script>
|
||||
|
||||
</article>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user