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

Copy/paste from custom titlebar doesn't work in markdown previews #105603

Open
clandrew opened this issue Aug 28, 2020 · 11 comments
Open

Copy/paste from custom titlebar doesn't work in markdown previews #105603

clandrew opened this issue Aug 28, 2020 · 11 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities titlebar VS Code main title bar issues webview Webview issues windows VS Code on Windows issues
Milestone

Comments

@clandrew
Copy link

clandrew commented Aug 28, 2020

Issue Type: Bug

  1. Open a markdown file for editing
  2. Open the preview view
  3. Select some text in the preview
  4. Choose context menu entry "Copy"
  5. Navigate to external program
  6. Paste

Expected: text from VSCode appears
Actual: Only a blank space is pasted

VS Code version: Code 1.47.3 (91899dc, 2020-07-23T13:12:49.994Z)
OS version: Windows_NT x64 10.0.20185

@clandrew
Copy link
Author

Issue persists after update to July 2020 (version 1.48)

@clandrew clandrew changed the title Can't copy from markdown preview using hotkey or right click Can't copy from markdown preview using Edit->Copy menu item Aug 28, 2020
@clandrew
Copy link
Author

Looked at it more, I think I understand the issue now. There's a problem with how it treats window focus. If the selected text is blue (using default coloring scheme), I can copy it using Ctrl+C . However, if the selected text is grey (using default coloring scheme), I can not copy it.

Both are used as selection colors, but "Blue" is more focused than "Grey"

The big plot twist: Clicking anywhere in the context menu changes your selection from "Blue" to "Grey"

@clandrew
Copy link
Author

VSCode2

Showing some copying behavior

  • Select a word by click and drag then Ctrl+C == OK
  • Select a word by doubleclicking then Ctrl+C == Just the word is shown as selected (in grey), the whole paragraph is copied
  • Select a word by click and drag then Edit->Copy == A blank line is copied

@mjbvz mjbvz added bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities webview Webview issues windows VS Code on Windows issues labels Sep 28, 2020
@mjbvz mjbvz added this to the Backlog milestone Sep 28, 2020
@mjbvz
Copy link
Contributor

mjbvz commented Sep 28, 2020

Only happens to me when using the custom title bar (which is the default on Windows)

@turara
Copy link
Contributor

turara commented Oct 1, 2020

This seems correct behavior when doubleClickToSwitchToEditor setting is on.

スクリーンショット 2020-10-01 23 38 44

  1. Double clicking a word will move focus to source markdown file.
  2. Copy command copies a whole line in an editor when nothing is selected. (Is this correct behavior?)

A related bug

The cursor jumps into wrong line in the source markdown file when you click a word at the end of the long long sentence. For example, double clicking the last word of the sentence in the gif animation clandrew posted, will move the cursor to the line 4 of the markdown file.

This is because getEditorLineNumberForPageOffset function calculates line number by interior division of clicked position using previous/next code-line bounds.

const line = getEditorLineNumberForPageOffset(offset);

I think this bug can be solved by simply calculating the nearest line of clicked position with function like

export function getNearestEditorLineNumberOfPageOffset(offset: number): number {
	const { previous, next } = getLineElementsAtPageOffset(offset);
	if (!next) {
		return previous.line;
	}

	const previousBounds = getElementBounds(previous);
	const previousBottom = previousBounds.top + previousBounds.height + window.scrollY;
	const nextTop = getElementBounds(next).top + window.scrollY;

	if ((offset - previousBottom) <= (nextTop - offset)) {
		return previous.line;
	} else {
		return next.line;
	}
}

Is it OK to make a PR to fix this?

@clandrew
Copy link
Author

clandrew commented Oct 1, 2020

@turara I have that setting turned on but still repro the problem (selecting text in Preview then clicking Edit->Copy causes only a blank line to be copied)

@turara
Copy link
Contributor

turara commented Oct 2, 2020

@clandrew Hmm. On my macOS, clicking Edit menu dose not steal focus 🤔

I think if you have that setting turned off, at least the following problem is solved.

Select a word by doubleclicking then Ctrl+C == Just the word is shown as selected (in grey), the whole paragraph is copied

@clandrew
Copy link
Author

clandrew commented Oct 7, 2020

@turara Ok yeah that's interesting if true, could help narrow things down.
I have half a mind to factor the paragraph copying into a separate bug.
In the beginning it seemed related to the Edit->Copy menu item problem but now I'm beginning to think it is not.

@clandrew clandrew changed the title Can't copy from markdown preview using Edit->Copy menu item Markdown preview copypaste is broken Nov 19, 2020
@winstonhenke
Copy link

winstonhenke commented Dec 27, 2020

Also seeing this issue.

MacOS: 11.1
VS Code: 1.52.1

@clandrew
Copy link
Author

Still broken on 1.56.2

I renamed this bug to better reflect what was going on. The work-around suggested by turara concerns a different problem I mentioned in passing which is unrelated to the bug.

@iamCristYe
Copy link
Contributor

still broken (1.58.2)
Any plan to fix this?

@mjbvz mjbvz changed the title Markdown preview copypaste is broken Copy/page from custom menu bar doesn't work in markdown previews Oct 19, 2021
@mjbvz mjbvz added the menus Menu items and widget issues label Oct 19, 2021
@mjbvz mjbvz changed the title Copy/page from custom menu bar doesn't work in markdown previews Copy/page from custom titlebar doesn't work in markdown previews Oct 19, 2021
@mjbvz mjbvz added titlebar VS Code main title bar issues and removed menus Menu items and widget issues labels Oct 19, 2021
@mjbvz mjbvz changed the title Copy/page from custom titlebar doesn't work in markdown previews Copy/paste from custom titlebar doesn't work in markdown previews Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities titlebar VS Code main title bar issues webview Webview issues windows VS Code on Windows issues
Projects
None yet
Development

No branches or pull requests

5 participants