NSTextView: copying a list item does not include list formatting on paste

123 Views Asked by At

I have a basic Mac app with a stock NSTextView ("Rich Document Content Text View" in Interface Builder), but I have also observed this behavior in TextEdit:

  1. Create a new bulleted list with 3 items
  2. Select and copy a single list item
  3. Paste the list item into the same document

→ The pasted item loses its list formatting, i.e. when I press Return at the end, no new list item is automatically added.

→ When I select two or more list items, it works correctly.

Here's a quick video:

NSTextView pasting a list item

Other observations

I tested the same procedure in Scrivener (which I believe also uses NSTextView), and here copying a single list item places the correct formatting list attributes on the clipboard.

I inspected the clipboard and when I copy a single list item, indeed, the RTF contents are different compared with Scrivener.

NSTextView (one item copied):

\f0\fs36 \cf0   \'95    Regular list item}

Scrivener (one item copied):

\f0\fs32 \cf0 {\listtext    \uc0\u8226  }Regular list item}

Note how Scrivener places the correct formatting on the clipboard.

NSTextView (two items copied):

\f0\fs36 \cf0 {\listtext    \uc0\u8226  }Regular list item\
{\listtext  \uc0\u8226  }Another list item}

When copying two list items, it works as expected.

What am I missing? Or is this a bug/feature and the Scrivener folks are working around this in their app (e.g. detecting when a single list item is copied and fixing its attributes)?

1

There are 1 best solutions below

0
On BEST ANSWER

It's a "feature".

Try placing your cursor at the start (rather than the end of the line) and dragging down to select the line, copy, paste - you'll get a return at the end of the paste but if you back up to the end of the pasted line and hit return you'll find you get the list formatting.

The formatting details for a "paragraph" are attached to the newlines, also when text is copied formatting info for the start of the selection is included.

The source of TextEdit is available from Apple, the linked version is a few years old and Apple's documentation archive, you might find a newer version in the new "improved" documentation Apple provides, or lose your sanity looking ;-(. If you read it you can find out how these features/quirks of the text system are dealt with.

HTH