Page MenuHomePhabricator

Cursor position sometimes gets lost when switching from temporary wikitext editor to final editor
Open, Needs TriagePublic

Description

Steps to reproduce:

  1. Open a page for editing in NWE.
  2. Place the cursor somewhere in the page, while it is still loading.
  3. Optionally: Type one letter.
  4. Wait until the final editor is loaded.

Expected:
The cursor stays in the same place, your edit from step 3 is kept.

Actual:
Sometimes, the cursor is instead reset to the start of the article. When you typed one letter, that letter may be lost, but instead the cursor advances by one place, i.e. is placed after the first letter.

I'm not able to reliably reproduce the issue, especially since the editor loads so fast for me that most of the time it is hard to execute all the above steps while the temporary editor is still in use.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Do you have syntax highlight enabled?

I can't see a mechanism for it happening without syntax highlighting, as as soon as we read out the content and the last selection, we disable the textarea.

Deskana changed the task status from Open to Stalled.May 8 2018, 6:42 PM
Deskana subscribed.

Stalled pending more instructions on how to reproduce.

Do you have syntax highlight enabled?

It happens both with and without syntax highlight, so unless CodeMirror does something even when present only disabled, it doesn't have anything to do with it.

The best way to avoid this bug seems to be to try to reproduce it ...

I think it is something that happens after https://gerrit.wikimedia.org/g/mediawiki/extensions/VisualEditor/+/master/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js#147, but before https://gerrit.wikimedia.org/g/mediawiki/extensions/VisualEditor/+/master/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js#469. It's obvious that any cursor change between these two points will be ignored, but I have no idea how much time there is between them.

I also have "search as you type" enabled in Firefox, so when I type something while the temporary editor is read-only, this will invoke the search, and so moves the focus. So this setting might have something to do with this issue.

Ryasmeen changed the task status from Stalled to Open.EditedMay 9 2018, 4:45 PM
Ryasmeen subscribed.

Yup, it is reproducible following the steps mentioned in the report when I have syntax highlighting on. But yeah, I had to do it super fast to make it happen :)
Also after that point the cursor starts acting completely weird. Here is a video capture to show what happens:

@Ryasmeen In your video you don't appear to be using the temporary wikitext editor (the one that shows before the toolbar is ready), and also syntax highlighting is enabled, so that would appears to be a separate bug (probably with SyntaxHighlighting).

The best way to avoid this bug seems to be to try to reproduce it ...

I think it is something that happens after https://gerrit.wikimedia.org/g/mediawiki/extensions/VisualEditor/+/master/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js#147, but before https://gerrit.wikimedia.org/g/mediawiki/extensions/VisualEditor/+/master/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js#469. It's obvious that any cursor change between these two points will be ignored, but I have no idea how much time there is between them.

I also have "search as you type" enabled in Firefox, so when I type something while the temporary editor is read-only, this will invoke the search, and so moves the focus. So this setting might have something to do with this issue.

In the first call you link to we do tempWikitextEditor.$element.prop( 'readonly', true ); which means no more input is allowed. (I note that in Firefox you can still move the cursor, but that would manifest as a different issue).

It's possible the user is able to type into the real surface before the data from the temp surface is written to it.... No, we write the data directly into the API response object.

The best way to avoid this bug seems to be to try to reproduce it ...

I think it is something that happens after https://gerrit.wikimedia.org/g/mediawiki/extensions/VisualEditor/+/master/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js#147, but before https://gerrit.wikimedia.org/g/mediawiki/extensions/VisualEditor/+/master/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js#469. It's obvious that any cursor change between these two points will be ignored, but I have no idea how much time there is between them.

I also have "search as you type" enabled in Firefox, so when I type something while the temporary editor is read-only, this will invoke the search, and so moves the focus. So this setting might have something to do with this issue.

In the first call you link to we do tempWikitextEditor.$element.prop( 'readonly', true ); which means no more input is allowed. (I note that in Firefox you can still move the cursor, but that would manifest as a different issue).

The fact Firefox allows moving the cursor in a readonly textarea does explain this issue:

  • The temporary editor loads, with the cursor at the start of the text.
  • syncTempWikitextEditor is called, the cursor position (= 0) is stored, the textarea is set readonly.
  • I put the cursor somewhere (which I can, because the textarea is just readonly and not disabled).
  • afterActivate is called, and sets the cursor to the stored position, i.e. resets to the start of the text
Vvjjkkii renamed this task from Cursor position sometimes gets lost when switching from temporary wikitext editor to final editor to 1edaaaaaaa.Jul 1 2018, 1:11 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from 1edaaaaaaa to Cursor position sometimes gets lost when switching from temporary wikitext editor to final editor.Jul 3 2018, 12:15 AM