Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot match multiple selections during copy/paste if whole line is selected #2697

Closed
redmunds opened this issue Jul 13, 2014 · 11 comments
Closed

Comments

@redmunds
Copy link
Contributor

This is captured in Brackets issue: adobe/brackets#7923

Recipe:

aaa

bbb

  1. Start with text above:
  2. Create a multiple selection with 2 selection: each line of text (including newlines) & Copy
  3. Create another multiple selection with 2 selections to match first selection & Paste

Result:
Both lines are pasted in each new selection

Expected:
First line is pasted into first selection and second line is pasted in second selection

This seems to be a design flaw since the selection separator is the same as the newline char.

@marijnh
Copy link
Member

marijnh commented Jul 14, 2014

I am aware of this problem, but since we can't store extra meta info in the clipboard, I do not know of a sane solution. Do you have a proposal?

@redmunds
Copy link
Contributor Author

For this particular case, when determining the number of selections on clipboard code could detect when newline is followed by another newline or end-of-text and interpret that the newline is part of selection and not a selection separator.

Of course, this only fixes the case where selection ends in a newline, but that is a common case for me, personally, so I think it's worth considering.

I guess this assumption is not true if selection contains a multi-line selection with empty lines, but the handling of that case doesn't seem any worse that the way it is now. For example, in recipe above, if you have 4 selections/cursors when pasting, then a match is detected and each part of copied selection is only pasted once.

@marijnh
Copy link
Member

marijnh commented Jul 14, 2014

(Background: I hesitated to add this feature -- splitting pasted content across cursors -- at all, since it is fundamentally kludgy, due to the code's inability to determine what the user is trying to do.)

Adding a special case for this specific situation does not sound like an improvement to me. I don't agree that it is a common case. Why would pasting multi-line ranges where the range is a single line ending in a newline be more common than two lines ending in a newline, or chunks of random size?

@redmunds
Copy link
Contributor Author

As I said, "multi-line ranges where the range is a single line ending in a newline" is a common case for me, and the handling of the other cases may be a little different, but it's already broken (based on my expectations) so I don't think it's any worse.

The only other ways I can think to fix this are:

  • Create a custom clipboard format, but that would break interoperability across other apps, so that's not a good solution
  • Store a "numberOfSelectionsInLastCopy" value. This would have to be cleared whenever focus leaves app to best handled clipboard data from other apps.

@marijnh
Copy link
Member

marijnh commented Jul 15, 2014

Keeping track of our own copying, so that copy-pastes within CodeMirror (on a single page) at least do the right thing is a good idea. Could you take a look at the attached patch, and tell me if it helps for you?

@redmunds
Copy link
Contributor Author

Patch works great! I couldn't find any unexpected behavior. Thanks.

@redmunds
Copy link
Contributor Author

One other change I think would be useful would be to not only match exact number of selections for copy/paste, but also to match exact multiples. For example:

Start with multiple selection with 2 selections: <span class="foo"> and </span> and Copy. Create another multiple selection with 4 cursors (where vertical bars are the cursors):

<p>aaa |bbb| ccc |ddd| eee</p>

Paste results in:

<p>aaa <span class="foo">bbb</span> ccc <span class="foo">ddd</span> eee</p>

@marijnh
Copy link
Member

marijnh commented Jul 20, 2014

Sublime Text does not seem to do the multiple-of-clipboard thing you describe. Is there a precedent for it?

@redmunds
Copy link
Contributor Author

No precedent. This would distinguish CodeMirror from Sublime!

marijnh added a commit that referenced this issue Jul 21, 2014
@marijnh
Copy link
Member

marijnh commented Jul 21, 2014

I'm only willing to do this for recognized selections that have a known set of ranges (not outside clipboard data), since the potential for false positives becomes a bit too high in the other case.

That does cause the problem that people will be surprised when this works from CM itself but not from Sublime Text or another external editor. I'm not sure how often such confusion will come up. I've added the feature for now, but am reserving the right to back it out at a later time.

@marijnh marijnh closed this as completed Jul 21, 2014
@redmunds
Copy link
Contributor Author

Thanks! Fair enough. I predict that CodeMirror will become the precedent that Sublime Text copies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants