Page MenuHomePhabricator

insertTags shift cursor position to start of the line
Closed, ResolvedPublic

Description

  1. Go to the 2010 WikiEditor
  2. Enable syntax highlight
  3. Move to the end of a line
  4. Click <ref></ref> listed beneath the edit area
  5. Notice the block is inserted, but the cursor moves to the front of the line.

Suspect this is because our setSelection calls setFocus AFTER moving the cursor. Googling suggests you should always focus before moving the cursor.
https://stackoverflow.com/questions/33394855/how-to-set-cursor-position-in-codemirror-editor

Event Timeline

TheDJ created this task.Jun 14 2018, 7:58 PM
Restricted Application added a project: Community-Tech. · View Herald TranscriptJun 14 2018, 7:58 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Niharika added a subscriber: Niharika.

Thanks @TheDJ. I can reproduce the bug.

I was just debugging this. The <ref></ref> link is put there by ChartInsert, right?

In one of my own user scripts, I only had to change the way I was getting the cursor position (diff) so that it knew where to set it. Maybe not the same issue. The gadget on enwiki appears to use charinsert-core.js, and I can't find the relevant code there.

TheDJ added a comment.Jun 14 2018, 8:13 PM

It's not the same issue I think. I had breakpoints on all the textSelection functions and this setSelection is the last in the sequence, and I just verified with codemirror.doc.getCursor() in the console that the setFocus() causes the move of the cursor.

Change 440750 had a related patch set uploaded (by TheDJ; owner: TheDJ):
[mediawiki/extensions/CodeMirror@master] Focus before setting the cursor/selection

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

TheDJ triaged this task as Low priority.Jun 17 2018, 4:12 PM

Change 440750 merged by jenkins-bot:
[mediawiki/extensions/CodeMirror@master] Focus before setting the cursor/selection

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

Vvjjkkii renamed this task from insertTags shift cursor position to start of the line to szaaaaaaaa.Jul 1 2018, 1:03 AM
Vvjjkkii raised the priority of this task from Low to High.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed subscribers: gerritbot, Aklapper.
CommunityTechBot renamed this task from szaaaaaaaa to insertTags shift cursor position to start of the line.Jul 2 2018, 12:10 PM
CommunityTechBot lowered the priority of this task from High to Low.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added subscribers: gerritbot, Aklapper.
Niharika closed this task as Resolved.Jul 3 2018, 11:41 PM
Niharika claimed this task.
Niharika moved this task from To Be Estimated/Discussed to Archive on the Community-Tech board.