WordPress.org

Make WordPress Core

Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#23054 closed defect (bug) (fixed)

Cursor position after editing media library attachment details

Reported by: GeraldS Owned by: nacin
Milestone: 3.5.1 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

After editing the caption of an attachment in the media library insert dialog the cursor jumps to the wrong position when you click in another field.

Steps to reproduce:

  • create/edit a post
  • open the "insert media" dialog
  • select an image
  • enter text in the "caption" field
  • click in the "alt text" (or "description") field

Expected behavior:

  • the cursor should be in the clicked field, ready to accept text

Instead:

  • the cursor jumps to the beginning of the text in the "caption" field

I confirmed this behavior with three separate installations on different servers and with the default theme, no plugins activated.

Attachments (3)

23054.diff (1.4 KB) - added by lessbloat 16 months ago.
23054.2.diff (1.1 KB) - added by koopersmith 16 months ago.
23054.3.diff (1.5 KB) - added by koopersmith 16 months ago.

Download all attachments as: .zip

Change History (10)

comment:1 SergeyBiryukov16 months ago

Confirmed. Clicking another field after editing Caption causes the spinner and the "Saved" message to appear, but the cursor stays in the previous field.

Only happens with Title and Caption fields. Editing Alt Text and Description seems to work correctly.

The results are a bit inconsistent with different browsers:

  • In Firefox 17, when editing Title or Caption and clicking another field, the cursor jumps to the beginning of the text.
  • In Chrome 23, when editing Caption and clicking another field, the cursor jumps to the beginning of the text. When editing Title and clicking another field, the text become selected.
  • In IE 8, when editing Title or Caption and clicking another field, the cursor disappears.
  • In Opera 12, when editing Caption and clicking another field, the cursor stays at the end of the text. When editing Title and clicking another field, the cursor jumps to the beginning of the text.

comment:2 SergeyBiryukov16 months ago

  • Milestone changed from Awaiting Review to 3.5.1

comment:3 alexvorn216 months ago

  • Keywords needs-patch added

lessbloat16 months ago

comment:4 lessbloat16 months ago

It looks like the change events on [data-setting] call updateSetting() which then saves the model, which then re-renders the view.

If we could add a click event, we could record the field that was clicked and add the focus there after the view re-renders.

Unfortunately you can't just add a click event because the change event fires when the focus is lost (re-rendering the view), before the click event can fire.

23054.diff adds a 50ms delay (which is a bit of a hack) allowing the click event to fire before the modal is saved and the view is re-rendered.

I also removed the 'change [data-setting]' event. It was breaking the spinner/save functionality (and I can't really figure out why it's there - hopefully someone can enlighten me).

As far as I can tell, this patch works, but it's hacky, and could very likely be improved.

Version 0, edited 16 months ago by lessbloat (next)

koopersmith16 months ago

koopersmith16 months ago

comment:5 nacin16 months ago

  • Keywords has-patch commit added; needs-patch removed

23054.3.diff is lovely.

This only affected titles and captions because those fields were re-rendered in case there were describable elements ("Describe this file" / "Caption this image"), as we would need to sync those fields. We can skip the re-render whenever the attachment view being rendered has the same value as the model, which would be the case for the view being edited. And if there's only one visible view, then there's no re-rendering at all.

This might also render some of our brute-force make-tabbing-work code obsolete, which we can look into during 3.6.

comment:6 nacin16 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 23283:

Don't unnecessarily re-render the attachment details view when editing the title and caption. Re-rendering causes issues with tabbing and focus, and is only necessary for other views (such as "Caption this image..." when editing a gallery).

props koopersmith.
fixes #23054.
for trunk.

comment:7 nacin16 months ago

In 23284:

Don't unnecessarily re-render the attachment details view when editing the title and caption. Re-rendering causes issues with tabbing and focus, and is only necessary for other views (such as "Caption this image..." when editing a gallery).

Merges [23283] to the 3.5 branch.

props koopersmith.
fixes #23054.

Note: See TracTickets for help on using tickets.