While working on T270317, I realized the performance of the
matchbrackets addon is not as good as described in
T270237#6739993. The issue with my original benchmark was that
I did it with a single pair of brackets with thousands of
characters between. A paragraph with thousands of brackets
behaves much worse. So bad that I feels painful when moving
the cursor.
Lowering the limit to something in the middle (between the
original 1000 and my 10000) makes it behave much, much better
on my machine.
Bug: T270237
Bug: T270317
Change-Id: I31f850f4c7778d6b5ff1d0eb17fdaf0edf7ae019
My upstream patch was accepted within 9 minutes:
https://github.com/codemirror/CodeMirror/pull/6565
Note: This backport includes another upstream commit that fixed
some typos.
Bug: T269096
Change-Id: Ib5b64214d7536bc952886f45290d537eab2f9bbb
The addon does have 3 settings:
- maxHighlightLineLength is for the current line where the
cursor is. Bracket matching is simply not done when the
current line is longer. The default is 1000, which is rather
low.
- maxScanLineLength is for every other line that is scanned in
the process. I don't understand why, but this limit is 10x
higher.
- maxScanLines is the number of lines that can be scanned.
Simply raising the first to be 10000 as well fixes our issue.
Note that CodeMirror does have a limit of 10000 anyway. It's
called maxHighlightLength there. Lines that are longer get
syntax highlighting only for the first 10000 characters. The
rest of the line is black. Using the same limit in the addon
makes it's behavior consistent. Means: The user can see when
the syntax highlighting stops, and bracket matching stops
working the same time.
I benchmarked with both settings. It doesn't have a measurable
effect. Bracket matching is done in <1ms in both cases.
Bug: T270237
Change-Id: Ia56bf4c2fb023c9f117376242221d39f51196173
Less ambiguous variable names. Less duplication. The minor
issues have been introduced in T270317.
Bug: T270317
Change-Id: I366396a61b76e19293ce8d14c2f346b97498fe40
I continued profiling the matchbrackets addon for T270237 and run into
performance issues that turned out to be unrelated to the addon. The
flame graph highlighted a "match" function. Note this is not the
String.match() from JavaScript, but something in the CodeMirror lib:
StringStream.prototype.match = function (pattern) {
var match = this.string.match(pattern);
if (match && match.index > 0) {
return null;
}
return match;
}
(Note: I simplified this code so we can focus on the bug.)
When the pattern is a regular expression, it's executed via
JavaScript's String.match(). The function then checks if there was a
match and if it's at the start of the string. If not, it's not a
match and doesn't return one.
In other words: Even if there is a match somewhere in the string, the
function acts as if there was no match.
When we change all patterns to be anchored via ^, they don't scan the
entire string any more but return much ealier when there is no match
at the start of the string. We are effectively replacing nested loops
(hidden in the patterns) with single calls.
This bug exists since 2014.
The disabled line in the matchbrackets addon is just dead code. I
don't remove it to document the fact that we disabled it.
Bug: T270237
Bug: T270317
Change-Id: Icbb1122e6a3b26c0606726ff405e108931d185be
The addon does support some configuration options. These are passed
as properties of the `matchBrackets` CodeMirror option. Just passing
the boolean there hides that fact.
Bug: T270317
Bug: T270237
Change-Id: Iaa4b5ed8ef538e76cd1c96a09485e143112f1ae0
This patch also removes all remaining FIXMEs. This code is not
a bottleneck. There is nothing to do.
Bug: T270317
Change-Id: Ie034440c98d8064a22811a1b569237dddb7b7436
We "forgot" to update this addon when we did the update in
I6f0f030 (T258999).
Bug: T258999
Bug: T270317
Change-Id: Iab29e9e36f34b76551ddac497e40dc76669ba7c7
Basic tests to show that the highlighting classes have been attached
to the expected elements.
TODO in later patches:
* tests for the wikitext 2017 editor
Bug: T270240
Change-Id: I01ebd9881d38dd877f19ee3bb4fdcbb74d43afaf
Optimizations for the code introduced in Ic403e0a:
* Skip this entirely when something is selected (as discussed
in Ic403e0a).
* Use a combination of existing methods. I benchmarked these
again. This approach is "significantly" slower compared to
the custom code from before. However, "significantly" here
means something like 1 nanosecond vs. 4 nanoseconds. Both
is effectively nothing.
* Use the same approach in another place. This one is triggered
every time a change is made, e.g. a character typed. I
benchmarked this as well. The new code is about 500x faster
(yes, seriously).
Bug: T269094
Change-Id: I00fe595a89be7a257e27ed28d38568c81483338b
This is a convenient way to propagate alternate configuration during
browser testing.
Bug: T270240
Change-Id: Ica6399c53499be7f930e8d13b838ad265b66cdf4
The fallback technique makes the whole edit surface semi-transparent,
so reset native selections to full opacity.
Change-Id: If6cd585b1a09c549781fe82a3bdf18d64ac597b5
* using CodeMirror addon matchBrackets
* highlights the matching bracket of a pair
* highlights brackets when cursor is inside a pair
* feature usable in source code editor
Bug: T261857
Change-Id: Ib01d9919a47bb29684b54501644b01936b57972a
I had to make some CSS selectors more specific, because the
library changed
.CodeMirror pre
to
.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like
This is only relevant for entire lines (implemented as <pre>
elements). Most of the custom CSS is for characters, not lines.
In my tests in the Wikitext editor as well as VisualEditor I
could not spot any difference between the old and new version.
Bug: T258999
Change-Id: I6f0f030f972838727f3ef220feb105264f122798
* grunt-stylelint: 0.15.0 → 0.16.0
* stylelint-config-wikimedia: 0.10.1 → 0.10.3
The following rules are failing and were disabled:
* unit-disallowed-list
Change-Id: I5a9fb77b79121a25846d0ab6a85cbfe70b9624c6