Page MenuHomePhabricator

Toolbar/charinsert don't handle CodeMirror's multiple selections/cursors
Closed, ResolvedPublic

Description

Steps to reproduce:

  1. Edit any wiki page in normal mode, like https://en.wikipedia.org/w/index.php?title=Wikipedia&action=edit&section=1, with CodeMirror on.
  2. Select two words in different places: select one word with the mouse, press Ctrl (โŒ˜ on Mac), select another word.
    image.png (55ร—538 px, 7 KB)
  3. Press B icon on the toolbar to bold them.

Expected result:
Words become enclosed in ''', like this:

image.png (55ร—616 px, 7 KB)

Actual result:
Both words are inserted into both cursor positions, like this:

image.png (91ร—433 px, 8 KB)

Browser: Chrome on Windows 10.

The same applies to the <charinsert> tags.

Note that the new wikitext mode doesn't seem to support multiple cursors.

QA Results - Beta

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald Transcript
Jack_who_built_the_house renamed this task from Toolbar/charinsert don't handle CodeMirrors's multiple selections/cursors to Toolbar/charinsert don't handle CodeMirror's multiple selections/cursors.Dec 5 2018, 2:34 PM
Jack_who_built_the_house updated the task description. (Show Details)

Wow never knew CodeMirror supported this.. impressive. (cmd instead of ctrl on MacOSX btw).

Not sure if this can be supported, as jQuery.textSelection only supports a single selection.

Bhsd subscribed.

The current CodeMirror 6 integration does not support multiple selections any more. Do we want to add this functionality back with allowMultipleSelections and drawSelection?

The current CodeMirror 6 integration does not support multiple selections any more. Do we want to add this functionality back with allowMultipleSelections and drawSelection?

Yes, especially if it existed before. I, like TheDJ, was not even aware of this! CM6 says there's a performance impact, but it seems fine at first glance. If it becomes a problem, we can always remove it. Patch incoming :)

This still won't fix the bug mentioned here, however, as per T211205#4806060 our jQuery.textSelection implementation doesn't support more than one selection :(

Change 1003103 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] CodeMirrorWikiEditor: add ext for multiple selections/cursors

https://gerrit.wikimedia.org/r/1003103

Change 1003103 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirrorWikiEditor: add extension for multiple selections/cursors

https://gerrit.wikimedia.org/r/1003103

For now, how about deselecting all secondary selections whenever replaceSelection is called? For example,

this.view.dispatch({
    selection: {
        anchor: this.view.state.selection.main.from,
        head: this.view.state.selection.main.to
    }
});
this.view.dispatch(
    this.view.state.replaceSelection(value)
);

Actually, it looks like CodeMirror just never implemented the encapsulateSelection method. I'm working on adding this now :)

Actually, it looks like CodeMirror just never implemented the encapsulateSelection method.

I think the problem is more than encapsulateSelection as the WikiEditor toolbar also has a functionality of regexp replacement.

Change 1003927 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] CodeMirror: partially implement jquery.textSelection 'encapsulateText'

https://gerrit.wikimedia.org/r/1003927

So, the core jQuery.textSelection implementation of encapsulateText applies its changes using replaceSelection etc., which CodeMirror already listens to. As was already pointed out, jQuery.textSelection does not support multiple cursors/selections, so of course it's not doing the right thing either (multiple cursors can exist natively, at least on Firefox/Ubuntu.) I began to think this was then a jQuery.textSelection issue, but it seems there's no standard to be said of for multiple cursors ala a JavaScript API, so something like CodeMirror is required for it to work given CM does the selections itself.

The above patch adds support, but I still wonder if there's some work that could be done in jQuery.textSelection.

I think the problem is more than encapsulateSelection as the WikiEditor toolbar also has a functionality of regexp replacement.

Indeed! If my understanding is correct, WikiEditor has some of its own magic as well that interferes with things, but the basic use case of bold/italics and what not should work now. Though I definitely think it's odd that this feature only works in CodeMirror when it comes to multiple cursors.

How is multiple selection meant to work in the case of the link inserter? i.e. follow the above steps but instead of hitting do . With the above patch it's slightly strange, but then it's probably a slightly strange thing to do anyway.

Change 1003927 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirror: partially implement $.textSelection 'encapsulateSelection'

https://gerrit.wikimedia.org/r/1003927

@MusikAnimal Please review below since things changed recently.

Status: โŒFAIL
Environment: Beta: 1.42.0-alpha (b23054d)
OS: macOS Sonoma 14.2.1
Browser: Chrome 122, Firefox 123, Safari 17.3, Edge 122
Skins. Vector 2022, Vector 2010, Minerva, Monobook, Timeless
Device: MBA M2
Emulated Device:: n/a
Test Links:
https://en.wikipedia.org/w/index.php?title=Wikipedia&action=edit&section=1
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Wikipedia&action=edit
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Dog&action=edit

โœ…AC1: https://phabricator.wikimedia.org/T211205

BetaProd
2024-02-27_09-14-32.png (1ร—1 px, 500 KB)
2024-02-26_14-56-21.png (1ร—1 px, 553 KB)

โŒ UPDATE- I'm not sure what happened an hour ago but the results now changed as seen in the webms below as they are all bold. The same results as Italics with Bold.

โ“Possible issue with other characters (ex. "รฅ", "ล“", "ฮฉ", "โˆซ") -Beta and Prod are the same, not sure if that's fine or not when you try to make these characters bold in code mirror. It added extra characters.

CharactersBeta- BoldProd- Bold
2024-02-27_09-27-33.png (1ร—1 px, 469 KB)
2024-02-27_09-29-12.png (1ร—1 px, 375 KB)
2024-02-27_09-28-27.png (1ร—1 px, 520 KB)

@GMikesell-WMF My apologies for the confusion! In order to test CodeMirror 6, you must do one of the following:

Things are getting more and more stable by the day, so we'll probably deploy to all Beta wikis in the near future.

@MusikAnimal Ok that seems to work. Before I move this to Done, check out the webm for when it's En-rtl.

Status: โŒ FAIL
Environment: Beta: 1.42.0-alpha (d5ff499)
OS: macOS Sonoma 14.2.1
Browser: Chrome 122, Firefox 123, Safari 17.3, Edge 122
Skins. Vector 2022, Vector 2010, Minerva, Monobook, Timeless
Device: MBA M2
Emulated Device:: n/a
Test Links:
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Dog&action=edit&cm6enable=1

โœ…AC1: https://phabricator.wikimedia.org/T211205

EdgeFirefoxSafariChromeGreek CharactersSection & Link words
2024-02-27_13-38-41.png (1ร—2 px, 675 KB)
2024-02-27_13-41-05.png (1ร—2 px, 742 KB)
2024-02-27_13-43-13.png (1ร—2 px, 717 KB)
2024-02-27_13-44-24.png (1ร—2 px, 711 KB)
2024-02-27_14-11-37.png (931ร—2 px, 460 KB)
2024-02-27_14-43-46.png (1ร—2 px, 491 KB)
Vector 2010MinvevaMonobookTimeless
2024-02-27_13-48-25.png (984ร—3 px, 875 KB)
2024-02-27_13-49-53.png (1ร—2 px, 400 KB)
2024-02-27_13-50-52.png (1ร—3 px, 905 KB)
2024-02-27_13-52-44.png (1ร—2 px, 515 KB)

โŒAC2: CodeMirror, Bold, En-rtl - Different letters were bold.
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Dog&action=edit&cm6enable=1&uselang=en-rtl

โŒAC2: CodeMirror, Bold, En-rtl - Different letters were bold.
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Dog&action=edit&cm6enable=1&uselang=en-rtl

Oh boy. So, I'm seeing a number of issuesโ€ฆ I've identified r1005841 (an unrelated patch) as causing a massive performance bottleneck, and I think the issue you're seeing is a side effect of that. I'm guessing the slow render caused the cursor to become offset with the view, or something. I'm investigating.

Oh boy. So, I'm seeing a number of issuesโ€ฆ I've identified r1005841 (an unrelated patch) as causing a massive performance bottleneck, and I think the issue you're seeing is a side effect of that. I'm guessing the slow render caused the cursor to become offset with the view, or something. I'm investigating.

Not a performance problem as it turns out, but some other weirdness. Anyway, things should work correctly now!

โŒAC2: CodeMirror, Bold, En-rtl - Different letters were bold.
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Dog&action=edit&cm6enable=1&uselang=en-rtl

As an aside, while testing RTL languages on a LTR wiki is great, it doesn't properly test the RTL environment unless the page language is also RTL. So for RTL testing, I would just use https://en-rtl.wikipedia.beta.wmflabs.org/. There you don't need to use the ?cm6enable=1 flag, either. (I'm also going to get CM6 deployed to all of Beta probably today, so soon you won't use the cm6enable parameter at all on Beta).

@MusikAnimal When it's an RTL interface with RTL language,I have no issues. The same goes with LTR. I do get issues when it's RTL interface with LTR language and vice versa which I created a separate task in T359589: CodeMirror 6: Cursor is offset when viewing a mix of LTR/RTL interfaces and page langauge. For this task, I will move this to Done and test the other task created when it has been resolved. Thanks for all your work!

Status: โœ…PASS
Environment: Beta: 1.42.0-alpha (ab3f8bd)
OS: macOS Sonoma 14.2.1
Browser: Chrome 122, Firefox 123, Safari 17.3, Edge 122
Skins. Vector 2022, Vector 2010, Minerva, Monobook, Timeless
Device: MBA M2
Emulated Device:: n/a
Test Links:
https://en-rtl.wikipedia.beta.wmflabs.org/w/index.php?title=I_Started_With_100K&action=edit
https://en.m.wikipedia.beta.wmflabs.org/wiki/Dog#

โœ…AC1: https://phabricator.wikimedia.org/T211205

Browser + interface in LTR + page language in LTRVector 2010MinervaMonobookTimeless
2024-03-07_12-42-11.png (1ร—2 px, 691 KB)
2024-03-07_12-43-51.png (1ร—2 px, 402 KB)
2024-03-07_12-53-54.png (1ร—3 px, 934 KB)
2024-03-07_12-55-46.png (1ร—2 px, 491 KB)
Browser + interface in RTL + page language in RTLVector 2010MinervaMonobookTimeless
2024-03-07_14-30-30.png (1ร—3 px, 693 KB)
2024-03-07_14-32-24.png (1ร—2 px, 392 KB)
2024-03-07_14-33-41.png (978ร—3 px, 665 KB)
2024-03-07_14-34-53.png (1ร—2 px, 515 KB)
SafariFirefoxEdge
image.png (1ร—2 px, 452 KB)
2024-03-07_14-40-10.png (1ร—2 px, 653 KB)
2024-03-07_14-39-11.png (1ร—2 px, 540 KB)

This is now fixed in CodeMirror 6, which will be slowly released in the coming weeks/months. We will not be backporting any changes to soon-to-deprecated CodeMirror 5, so I'm going to close this as resolved.

Note that WikiEditor's search/replace may not be compatible with CodeMirror's multiple selections, but this is a separate issue and should be filed under a separate task, if people really want it fixed. Using it without multiple cursors should be fine, as it uses the jQuery.textSelection which bubbles up to CodeMirror.

Using it without multiple cursors should be fine, as it uses the jQuery.textSelection which bubbles up to CodeMirror.

Unfortunately, no. The WikiEditor's replace, excluding replaceAll, completely ceases to work. In addition, inserting an image, a template, or a table is not working any more.

The WikiEditor's replace, excluding replaceAll, completely ceases to work. In addition, inserting an image, a template, or a table is not working any more.

Here I was just making assumptionsโ€ฆ thanks for testing! I have filed T359671 and will work on this next.