Commit graph

356 commits

Author SHA1 Message Date
ElijahPepe 2451c7f944 Reload CodeMirror to fix a caret issue
A common issue, reported in VPI as Possible Thursday weirdness, with
source editor users using syntax highlighting is that the caret can
often be misplaced as to where the user selects. This PR adds code
to reload CM when loaded to adjust for this behavior.
Moved to after CM has finished initialising. Tested working.
Add another instance of codeMirror.refresh().

Bug: T305333
Change-Id: I9a81ffd41a3ba1321b7b5744ba096583cbb1d96c
2022-04-05 22:37:31 +01:00
Sam Wilson 1310fbf645 Support WikiEditor's realtime-preview feature
Add support for enabling, resizing, and disabling the new
realtime-preview feature.

Bug: T293347
Bug: T303767
Change-Id: I8c8c25fe56be55a61f4b8d1d2ef8cf74483aa241
2022-03-24 12:02:03 +08:00
jenkins-bot bec93b7b5a Merge "build: Update devDependencies" 2022-03-16 20:35:03 +00:00
jenkins-bot fa9462342d Merge "Highlight headings with trailing comments" 2022-03-16 20:16:20 +00:00
Ed Sanders 80336b322a build: Update devDependencies
Change-Id: Ia0f3481cb4e153338ef68c1d44951d897ddc7195
2022-03-13 22:56:14 +00:00
AntiCompositeNumber a84828c08c
Highlight headings with trailing comments
Bug: T171074
Change-Id: I1c8399b839a9be5e5aa0ece36dc86a5848936b5f
2022-03-11 17:13:14 -05:00
jenkins-bot 5e28656544 Merge "Trigger focus/blur event handlers attached to textarea" 2022-03-10 22:53:23 +00:00
jenkins-bot c22868121e Merge "Highlight multi-line tags" 2022-03-04 21:09:42 +00:00
Thiemo Kreuz 20debba3b0 Enable eslint for our custom code in the matchbrackets addon
The resulting code style in this file is a little mixed. I tried to
stick to the existing style. Most notably is the indention with
2 spaces instead of 1 tab. But I couldn't disable the spaces inside
round brackets. They make the code so much more readable.

What this patch effectively does is enabling the eslint check for our
custom code in this addon, excluding all old code, and exclusing a few
rules that conflict to heavily with the old code style.

Change-Id: I12f953cb0a6fd35e405b6cc348abfb2c11e70696
2022-03-03 21:07:19 +00:00
bhsd d23dc77d16 Highlight multi-line tags
CodeMirror is already able to highlight multi-line tags if the tag name is followed by any non-whitespace characters in the same line. This commit fixes the other condition where the tag name is followed by whitespace only in the same line.

Bug: T201684
Change-Id: I8cb4a53ee0fe7fc8612a58331a1a3e57d00d7630
2022-02-23 17:02:22 -08:00
bhsd b9abcbc12e Trigger focus/blur event handlers attached to textarea
When CodeMirror is focused/blurred, the same event will triggered on its corresponding textarea.

Bug: T197632
Change-Id: Ib71b6774a60dd434bdc8a27b9eab433dcc1c65f0
2022-02-19 12:23:17 -08:00
bhsd ca0e8f20a4 Highlight tags in link text
HTML and extension tags should be highlighted as the text of internal or external links.

Bug: T184341
Change-Id: Ib1f2047936b395afd86720e2a7c921e382229cdd
2022-02-19 06:11:34 +00:00
Ed Sanders 0faac32661 eslint: Lint Gruntile.js using server rules
Change-Id: Ib0e7d62343689bb993476cb1ad40f93fc89a7190
2022-02-07 16:25:32 +00:00
Thiemo Kreuz 963e636f83 Restore focus also when switching syntax highlighting on
The same already happens when switching it off, see line #249.

I noticed there is still a (random?) chance the selection gets lost
when switching back and forth between syntax highlighting on and off.
This is not what this patch is about.

Bug: T298488
Change-Id: I541f96be9e6fb2f9032df4b86657d01f0eac5679
2022-01-03 18:00:26 +01:00
jenkins-bot 92051b550f Merge "Reduce noise in syntax highlighting tests" 2021-12-22 13:52:04 +00:00
Thiemo Kreuz be08e04309 Reduce noise in syntax highlighting tests
* What we care about is the <pre>. The class="CodeMirror-line" is
  added to every <pre>. We don't really learn anything new when we
  include it in our tests.
* Testing the ARIA role is testing a CodeMirror feature, not a
  feature of the mediawiki mode under test.

Change-Id: I33bfedb304228240c4e835cc983117668c398c61
2021-12-16 06:53:47 +00:00
jenkins-bot 0f70fd33e5 Merge "Fix syntax highlighting test failing when Cite isn't loaded" 2021-12-14 07:26:21 +00:00
Func 189bef8288 Set the line-break attr to initial
Now css rules applied to pre tags can easily affect the appearance of CodeMirror output, may intentionally or not.
With the line-break attr set to initial can make the appearance more stable, users can still override this with the more specific rules if they do want to.

Bug: T252965
Change-Id: If0d29ad152151c09ace2bcd32d2953ec3c9cf1aa
2021-12-12 09:06:20 +00:00
Thiemo Kreuz 0968d3ea16 Fix syntax highlighting test failing when Cite isn't loaded
I forgot this when I added this test case in I03a1e1a.

Also:
* Use another method to detect if the Cite extension is active. This
  is the same method used in the actual code.
* Move a line of code into the `if` it belongs to.

Change-Id: I1efd3f945150aeb08db3c771e579d9a6114a4c21
2021-12-09 10:06:41 +01:00
jenkins-bot 6ad7f542f2 Merge "Fix invalid reference to core resources/ directory" 2021-12-07 23:01:02 +00:00
Bartosz Dziewoński 561ffca718 Don't mess up the page when running tests via Special:JavaScriptTest
* Append to the hidden #qunit-fixture instead of directly to the body
* Use the right selector when cleaning up

Change-Id: I8be38900e6c5f4592f06dfc8f7c2cfc348627716
2021-12-07 14:40:11 +01:00
Derk-Jan Hartman 73441687ae Add q to list of allowed html elements to syntax highlighting
Bug: T289289
Change-Id: I2ab550c9e992a9daae76287313c596db67182d09
2021-12-04 22:17:26 +01:00
Timo Tijhof d97fa84d2b Fix invalid reference to core resources/ directory
This works by accident due to the CWD being mediawiki-core in most
cases during web requests, and Less.php implicitly falling back to that
as path expansion point when all attempts to expand the path fail (e.g.
relative to current file, and relative to a supported Less import dir
such as core `mediawiki.less/`.

Importing raw files from elsewhere in core is unstable, and is not
supported as this fails on some webserver configurations, as well as
in CLI contexts such as maintenance scripts that rebuild a cache, or
otherwise end up (in)directly computing part of a ResourceLoader
module.

The use case of themeing extension styles to the current skin (with
Vector using WikimediaUI) is subject of T112747 and T265941.

Follows-up I9eb07dd43.

Bug: T296639
Change-Id: I6d2be2941d6088b947ea7f18818add97f129760d
2021-11-30 00:58:58 +00:00
Thiemo Kreuz bab5c5232d Disable line numbering in all Android browser versions
This patch also minifies existing code. Note that [] is true in
JavaScript, unlike in PHP.

Bug: T285660
Change-Id: Ic80903ebd1364505fd4aaf7f53b53324a235fd79
2021-09-03 11:37:03 +00:00
WMDE-Fisch ade62be37e Improve text color & background in line numbers on VE
Bug: T287383
Change-Id: I1ece09c12bfbcb4709d5659d87f3045327729f10
2021-09-02 13:54:31 +02:00
jenkins-bot 79284952de Merge "Fire a hook when the CodeMirror editor is switched" 2021-07-13 04:39:52 +00:00
Inductiveload a57d7b7c1c Fire a hook when the CodeMirror editor is switched
This allows gadgets to react to the changing editor (for example
to rebind event handlers on the new active editor) without having
to use something like an MutationObserver.

Bug: T284282
Change-Id: I83f0a3c29b01031ae370b7d1207457586f0d25d6
2021-06-16 02:29:55 +01:00
Ed Sanders 3be6ae4b12 Move var declarations inline
Change-Id: I5a390c5621cefce1b396831654d54a74d0a63e9f
2021-06-15 15:50:09 +01:00
jenkins-bot 6fd33d774f Merge "Fix MediaWiki highlighter partly failing on quoted attributes" 2021-04-30 12:43:30 +00:00
Thiemo Kreuz 032bed3c61 Fix MediaWiki highlighter partly failing on quoted attributes
In T270880 an example with a slash in <ref name="a/b"> is
described. The same issue happens with several other characters
including the closing bracket, e.g. <ref name="a>b">. This patch
fixes all of this by accepting _all_ characters between double
and single quotes.

Bug: T270880
Change-Id: I03a1e1a25af692dc703b44a57b2d23d6fc15c8c9
2021-04-23 20:43:33 +02:00
jenkins-bot f569bf8d75 Merge "Fix bracket matching getting stuck when leaving the brackets" 2021-04-23 14:58:23 +00:00
Thiemo Kreuz 26a05d1dd0 Allow HTML comments and newlines in template names
Bug: T277767
Change-Id: I0a82af178d768e5f4d3dd81b1759c0ce72310397
2021-04-23 15:34:20 +02:00
Thiemo Kreuz 5186c6f3a2 Fix bracket matching getting stuck when leaving the brackets
Bug: T278840
Bug: T280978
Change-Id: Ia552fcd829ce38cbb7ac7fd7ebecad971a83e4c3
2021-04-23 14:48:23 +02:00
Adam Wight ed2f9944ea Enable line numbering only on configured namespaces
Introduces a new config variable `CodeMirrorLineNumberingNamespaces`
that can restrict line numbering to only appear for specified
namespaces.  Setting to null enables everywhere.

This takes some liberties with the `lib` module, turning it into a
container for shared functionality.  This can be pursued in later
work, by cleaning up duplicated code in this repo.

FIXME: failed to deduplicate the code for now.

Bug: T267911
Change-Id: Ida2b33eef38edc57d29756ec472c6f2c83bd7b11
2021-04-12 12:05:14 +02:00
Thiemo Kreuz 6937d0e51c Fix incomplete (auto)clear for highlighted brackets
The issue can be reproduced as described in T278840. What
happens is that an (auto)clear is triggered and removes all
marks, but the cached values in `currentMarks` remain. The next
time the same marks are found, they are discarded and don't
show up, because the cache says they are already there, when
they are not.

Bug: T278840
Change-Id: If83bd99e924f579854cfe4b01fab4ef86892933b
2021-04-09 11:07:26 +02:00
Adam Wight f2b6cec8f6 Reposition line numbering to be flush with the title
Bug: T267911
Change-Id: I8aab2f53ebba63a93f5a6bd63d616db801965ae0
2021-04-08 13:22:10 +02:00
Thiemo Kreuz 7365cc9a96 Enable line numbering
Line numbering will be unconditionally enabled.

Bug: T267911
Change-Id: I9eb07dd433e352ed5cea5dc978d469ee2ea6f347
2021-04-08 09:53:23 +02:00
jenkins-bot f1ef877d28 Merge "Update color scheme to meet accessibility standards" 2021-03-09 16:08:25 +00:00
WMDE-Fisch 9bea2a7905 Refine bracket matching styling
Adds a custom class for matched brackets to allow better integration
with custom bracket styles. The brackets won't be bold in the 2017WTE.
Bold font might lead to misalignment there. See ticket.

Note: box-shadow seems to be supported for quite some time by all
relevant browsers

Bug: T270926
Change-Id: Ica1e301f63a106a96db3bfaba4b2f322af64b009
2021-03-08 09:26:07 +01:00
Andrew Kostka aaf67a9c0b Update color scheme to meet accessibility standards
These changes to the color scheme are hidden behind a feature
flag for the time being.

Bug: T271895
Change-Id: I0a4b03e0f3bc8239f31edbbd5ae55661607b76f6
2021-03-05 16:39:14 +01:00
jenkins-bot 05241f1259 Merge "Add accesskey to CodeMirror input field" 2021-03-02 09:26:32 +00:00
Jon Harald Søby e325bc2e13 Add accesskey to CodeMirror input field
Add the same accesskey that the normal <textarea> uses.

Bug: T259347
Change-Id: I67c3b9d374203a5dabc29cc8c61fa76e2b64cb5a
2021-02-25 14:06:51 +01:00
jenkins-bot 92524135c0 Merge "Revert "Lower maxHighlightLineLength limit to 5000"" 2021-02-10 16:35:47 +00:00
Thiemo Kreuz (WMDE) 0268f68170 Revert "Lower maxHighlightLineLength limit to 5000"
This does not have an effect any more with all the other
optimizations in place.

This reverts commit 094f20902c.

Bug: T274369
Change-Id: I288039a35270093bd22b5a073e70f6b769088c13
2021-02-10 16:19:10 +00:00
Thiemo Kreuz cfecfbc099 Fix remaining bottleneck in wikitext syntax highlighter
I was wondering why the performance when editing wikitext is
still so bad, and profiled it again. Turns out
StringStream.match() is still the bottleneck (even if already
100 times better than before Icbb1122).

The method is called with many different patterns from
mode/mediawiki/mediawiki.js. I profiled them individually and
found a single outlier. The idea is the same as in Icbb1122.
A pattern that is able to find something *in* a string is
doing nothing but wasting time, as StringStream.match() ignores
every result that is not at the start of the string.

The change adds the missing ^ anchor and wraps the regex pattern
from mw.config.get( 'wgUrlProtocols' ) (that is something like
"ftp:\/\/|http:\/\/|https:\/\/|…") in (?:…), which is a
non-matching group. This is necessary because of the | in the
pattern. The result is a pattern that looks like /^(?:…|…|…)/i.

I remember looking at this code while working on Icbb1122, but
didn't include it in the patch, and then forgot about it.

Bug: T270237
Bug: T270317
Change-Id: Iea2fd116b68704c3186b0edf965006cc7c6eda82
2021-02-05 16:07:40 +01:00
Adam Wight 81bd2fe546 Clean-up: inline array merge
Change-Id: Ie976bf70f4117db09b53e6192f983930c7e6a458
2021-02-01 13:24:05 +01:00
jenkins-bot 96b81c3420 Merge "Log user edit count bucket" 2021-01-27 09:11:17 +00:00
Adam Wight 36212a7877 Log user edit count bucket
Bug: T269986
Change-Id: Iff3c983a59738312bc39bf65e2428526724fe139
2021-01-27 09:03:28 +00:00
Thiemo Kreuz 6bc81ffd50 Improve matchbrackets performance when moving the cursor
My previous patch Icbb1122 focused on the behavior of the
matchbrackets addon when the text is *edited*. This patch here
is about moving the cursor without changing the text. I
realized the addon re-draws everything every time the cursor
moves, even if the highlighted pair of brackets is still the
same. This triggers very expensive code in the CodeMirror lib.

I had a look at this expensive code, but did not found an easy
win. It just is what it is: an expensive re-draw. Instead I
introduced a caching layer that remembers the positions of the
previously highlighted brackets and bails out as early as
possible when nothing changed.

The biggest chunk of code is that "did something change?"
comparison. It looks expensive, but typically isn't. There are
typically only 2 elements in the array for a single
opening–closing pair. (Possibly more when there are multiple
text selections.) The elements in the two arrays are typically
in the same order. (Except the cursor is on the closing
bracket.) Which means the nested `every` → `for` loop will
typically be executed 2 times only – one time for each of the
2 elements.

I won't upload this change upstream because it is only relevant
together with our custom "in the middle" bracket highlighting.
With our customization we have many, many situations where the
highlighted brackets don't change. This (almost) doesn't happen
upstream.

Bug: T270317
Change-Id: I789b45362388f0818e797f789f6af427a35e3e06
2021-01-27 08:54:32 +00:00
Thiemo Kreuz 473a711aaa Rename our customized matchbrackets addon
Bug: T269096
Change-Id: I5b58099166f71ccc1b3b19334f28e8bbaafaceb3
2021-01-20 11:17:59 +01:00