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

Text line should be one text line when select/copy #2140

Closed
jviereck opened this issue Sep 18, 2012 · 7 comments
Closed

Text line should be one text line when select/copy #2140

jviereck opened this issue Sep 18, 2012 · 7 comments

Comments

@jviereck
Copy link
Contributor

If a line is made up of multiple divs, selecting, copy and past will result in multiple lines.

That the content of the divs ends up in multiple lines seems to be the case as we use absolute positioned divs.

@waddlesplash
Copy link
Contributor

When text changes style, too, you get at least a space, e.g.:
"blah blah blah"
will copy as
"blah bl ah blah"
losing both the formatting and the correct spacing.

Because of the nature of web browsers in terms of copy/paste, I think the only way to resolve this one is to do canvas-based text selection (#1205).

@jviereck
Copy link
Contributor Author

Because of the nature of web browsers in terms of copy/paste, I think the only way to resolve this one is to do canvas-based text selection (#1205).

It's also possible to handle the copy/cut "ourself" and not relay on the browser's default behavior. We can detect a copy/cut event, prevent the default one and make sure a custom created string gets copied. Then we can walk the selected text nodes, build them together in the right way.

Somewhat the lines:

var selNodes = window.getSelection().getRangeAt(0).cloneContents();

var copyStr = '';

for (var i = 0; i < selNodes.childNodes.length; i++) {
  var node = selNodes.childNodes[i];
  copyStr += node.textContent;
  if (node.getAttribute('new-line'))
    copyStr += '\n';
}

This doesn't handle offset starting/ending in the divs, but hopefully the basic idea is clear. The 'new-line' attribute is a attribute set on the div if the div is the last div in the line. This doesn't handle RTL text.

@yurydelendik
Copy link
Contributor

Because of the nature of web browsers in terms of copy/paste, I think the only way to resolve this one is to do canvas-based text selection (#1205).

Also, people are asking for caret browsing (F7 key) -- div text layer gives them that. As I understand, the caret mode is useful for accessibility as well.

@waddlesplash
Copy link
Contributor

It's also possible to handle the copy/cut "ourself" and not relay on
the browser's default behavior.

In the examples I've seen that attempted to do this, Firefox prevented
it. Even GitHub does not use JS copy/paste, their copy/paste buttons to
copy commit ID are Flash Player.

@aaronshaf
Copy link

If positioned span's were used instead of div's, I think this would be easier.

@luiscastro193
Copy link

I am trying to use a regex with the text of a PDF and I encountered this issue. Any known solution?

@timvandermeij
Copy link
Contributor

Fixed by #10197 since we're now using span element instead of div elements.

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

No branches or pull requests

6 participants