Commit 80f52654 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: allow copying visible text with styles in console

Console's custom copy handler tries to determine the selected text on
its own. In some cases, the browser's default copy handler offers much
better behavior:
- Include styles and colors
- Include table indentation that can be pasted into spreadsheet editors
- Account for text selections across shadow boundaries

Bug: 673746, 697149, 649828
Change-Id: I4b5e3a225234e28fe84197a73f655af9c4c9f418
Reviewed-on: https://chromium-review.googlesource.com/773462
Commit-Queue: Erik Luo <luoe@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517691}
parent 587f2238
...@@ -663,6 +663,10 @@ Console.ConsoleView = class extends UI.VBox { ...@@ -663,6 +663,10 @@ Console.ConsoleView = class extends UI.VBox {
contextMenu.defaultSection().appendAction('console.clear'); contextMenu.defaultSection().appendAction('console.clear');
contextMenu.defaultSection().appendAction('console.clear.history'); contextMenu.defaultSection().appendAction('console.clear.history');
contextMenu.saveSection().appendItem(Common.UIString('Save as...'), this._saveConsole.bind(this)); contextMenu.saveSection().appendItem(Common.UIString('Save as...'), this._saveConsole.bind(this));
if (this.element.hasSelection()) {
contextMenu.clipboardSection().appendItem(
Common.UIString('Copy visible styled selection'), this._viewport.copyWithStyles.bind(this._viewport));
}
var request = consoleMessage ? consoleMessage.request : null; var request = consoleMessage ? consoleMessage.request : null;
if (request && SDK.NetworkManager.canReplayRequest(request)) { if (request && SDK.NetworkManager.canReplayRequest(request)) {
......
...@@ -63,6 +63,7 @@ Console.ConsoleViewport = class { ...@@ -63,6 +63,7 @@ Console.ConsoleViewport = class {
this._headSelection = null; this._headSelection = null;
this._itemCount = 0; this._itemCount = 0;
this._cumulativeHeights = new Int32Array(0); this._cumulativeHeights = new Int32Array(0);
this._muteCopyHandler = false;
// Listen for any changes to descendants and trigger a refresh. This ensures // Listen for any changes to descendants and trigger a refresh. This ensures
// that items updated asynchronously will not break stick-to-bottom behavior // that items updated asynchronously will not break stick-to-bottom behavior
...@@ -89,10 +90,18 @@ Console.ConsoleViewport = class { ...@@ -89,10 +90,18 @@ Console.ConsoleViewport = class {
this._observer.disconnect(); this._observer.disconnect();
} }
copyWithStyles() {
this._muteCopyHandler = true;
this.element.ownerDocument.execCommand('copy');
this._muteCopyHandler = false;
}
/** /**
* @param {!Event} event * @param {!Event} event
*/ */
_onCopy(event) { _onCopy(event) {
if (this._muteCopyHandler)
return;
var text = this._selectedText(); var text = this._selectedText();
if (!text) if (!text)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment