Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Copy selection command to only write to clipboard if text selected - #8025

Merged
maxbrunsfeld merged 7 commits into
atom:masterfrom
lpommers:copy-selection-to-clipboard
Aug 18, 2015
Merged

maxbrunsfeld merged 7 commits into
atom:masterfrom
lpommers:copy-selection-to-clipboard

Conversation

@lpommers

Copy link
Copy Markdown

Closes #7103

Add a new command, editor:copy-selection, that writes to the clipboard only if the user has selected text

@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from 8e3d306 to e925735 Compare July 22, 2015 10:57
Comment thread src/text-editor.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why you decided to call copySelectedText() here instead of inlining the part for copying the line? Calling copySelectedText() will cause all selections to be processed again within that function, not just the selection currently being processed within copyOnlySelectedText(), right? While that normally won't be a performance problem, I think avoiding doing the same thing over and over again (since this would be a loop nested within the same loop) is always nice.

I also wonder if calling copySelectedText() here might cause problems in some cases because all selections will be processed according to the rules of that function, and not just by the rules of copyOnlySelectedText()? I'm thinking of cases with multiple selections, where one selection is empty and at the beginning of the line, and the other is empty but not at the beginning of the line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izuzak I decided to use copySelectedText() because I thought reusing code would be nicer than inlining that part, but I hadn't considered that it would process all selections again - so I think you're right - it would be best to avoid doing the same thing twice. I'll make some changes :)

@izuzak

izuzak commented Jul 22, 2015

Copy link
Copy Markdown
Contributor

cc @maxbrunsfeld for 👀 and 💭 since you were looking at #7103.

@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from e925735 to 2a3011a Compare July 27, 2015 11:04
@benogle benogle mentioned this pull request Aug 3, 2015
@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from 2a3011a to 2655513 Compare August 4, 2015 08:31
Comment thread src/text-editor.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that the maintainClipboard = true statement should be inside of the if not selection.isEmpty() block. Otherwise, if the first selection is empty and the second selection is not, the existing clipboard entry will be mutated unexpectedly.

@lpommers

Copy link
Copy Markdown
Author

@maxbrunsfeld this PR is now up to date based on your comment

Comment thread src/text-editor.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually like to not add this to our public API right now. Could you change Essential -> Private here?

Also, there's a small typo: hightlighted -> highlighted.

Also, I don't think the last sentence of the comment is true; it doesn't look like there's any special behavior of the cursor is at the beginning of the line. Did you intend to implement that behavior? If not, we should just remove that sentence from the comment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, in an earlier version of this branch, that comment was true - but then based on some feedback from what I read in the discussion in #7103 I removed it, so it's no longer true. I'll remove that and update the rest

@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from fd49935 to c38b2c0 Compare August 18, 2015 15:07
@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from c38b2c0 to 1a965ed Compare August 18, 2015 15:09
Comment thread src/text-editor.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this second blank line?

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Other than the placement of two \ns, this looks great. Thanks for taking the time to add this!

@lpommers

Copy link
Copy Markdown
Author

shoot, sorry about the newlines, i'll make a quick change and push

@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from d728d8c to 6e00880 Compare August 18, 2015 16:21
@lpommers
lpommers force-pushed the copy-selection-to-clipboard branch from 6e00880 to e96d6f5 Compare August 18, 2015 16:22
@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Great!

maxbrunsfeld pushed a commit that referenced this pull request Aug 18, 2015
Copy selection command to only write to clipboard if text selected
@izuzak

izuzak commented Aug 18, 2015

Copy link
Copy Markdown
Contributor

👏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants