Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 5 | import * as Common from '../common/common.js'; |
| 6 | import * as ObjectUI from '../object_ui/object_ui.js'; |
| 7 | import * as SDK from '../sdk/sdk.js'; |
| 8 | import * as TextUtils from '../text_utils/text_utils.js'; |
| 9 | import * as UI from '../ui/ui.js'; |
| 10 | |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 11 | const _PinSymbol = Symbol('pinSymbol'); |
| 12 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 13 | export class ConsolePinPane extends UI.ThrottledWidget.ThrottledWidget { |
Michael Liao | 5be6234 | 2019-10-22 23:24:29 | [diff] [blame] | 14 | /** |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 15 | * @param {!UI.Toolbar.ToolbarButton} liveExpressionButton |
Michael Liao | 5be6234 | 2019-10-22 23:24:29 | [diff] [blame] | 16 | */ |
| 17 | constructor(liveExpressionButton) { |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 18 | super(true, 250); |
Michael Liao | 5be6234 | 2019-10-22 23:24:29 | [diff] [blame] | 19 | this._liveExpressionButton = liveExpressionButton; |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 20 | this.registerRequiredCSS('console/consolePinPane.css'); |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 21 | this.registerRequiredCSS('object_ui/objectValue.css'); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 22 | this.contentElement.classList.add('console-pins', 'monospace'); |
| 23 | this.contentElement.addEventListener('contextmenu', this._contextMenuEventFired.bind(this), false); |
| 24 | |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 25 | /** @type {!Set<!ConsolePin>} */ |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 26 | this._pins = new Set(); |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 27 | this._pinsSetting = Common.Settings.Settings.instance().createLocalSetting('consolePins', []); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 28 | for (const expression of this._pinsSetting.get()) { |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 29 | this.addPin(expression); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 30 | } |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 31 | } |
| 32 | |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 33 | /** |
| 34 | * @override |
| 35 | */ |
| 36 | willHide() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 37 | for (const pin of this._pins) { |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 38 | pin.setHovered(false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 39 | } |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 40 | } |
| 41 | |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 42 | _savePins() { |
| 43 | const toSave = Array.from(this._pins).map(pin => pin.expression()); |
| 44 | this._pinsSetting.set(toSave); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param {!Event} event |
| 49 | */ |
| 50 | _contextMenuEventFired(event) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 51 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 52 | const target = event.deepElementFromPoint(); |
| 53 | if (target) { |
| 54 | const targetPinElement = target.enclosingNodeOrSelfWithClass('console-pin'); |
| 55 | if (targetPinElement) { |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 56 | const targetPin = targetPinElement[_PinSymbol]; |
Erik Luo | 212d281 | 2018-08-30 01:26:39 | [diff] [blame] | 57 | contextMenu.editSection().appendItem(ls`Edit expression`, targetPin.focus.bind(targetPin)); |
| 58 | contextMenu.editSection().appendItem(ls`Remove expression`, this._removePin.bind(this, targetPin)); |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 59 | targetPin.appendToContextMenu(contextMenu); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 60 | } |
| 61 | } |
Erik Luo | 212d281 | 2018-08-30 01:26:39 | [diff] [blame] | 62 | contextMenu.editSection().appendItem(ls`Remove all expressions`, this._removeAllPins.bind(this)); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 63 | contextMenu.show(); |
| 64 | } |
| 65 | |
| 66 | _removeAllPins() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 67 | for (const pin of this._pins) { |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 68 | this._removePin(pin); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 69 | } |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 73 | * @param {!ConsolePin} pin |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 74 | */ |
| 75 | _removePin(pin) { |
| 76 | pin.element().remove(); |
| 77 | this._pins.delete(pin); |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 78 | this._savePins(); |
Michael Liao | 5be6234 | 2019-10-22 23:24:29 | [diff] [blame] | 79 | this._liveExpressionButton.element.focus(); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @param {string} expression |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 84 | * @param {boolean=} userGesture |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 85 | */ |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 86 | addPin(expression, userGesture) { |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 87 | const pin = new ConsolePin(expression, this); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 88 | this.contentElement.appendChild(pin.element()); |
| 89 | this._pins.add(pin); |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 90 | this._savePins(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 91 | if (userGesture) { |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 92 | pin.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 93 | } |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 94 | this.update(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @override |
| 99 | */ |
| 100 | doUpdate() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 101 | if (!this._pins.size || !this.isShowing()) { |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 102 | return Promise.resolve(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 103 | } |
| 104 | if (this.isShowing()) { |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 105 | this.update(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 106 | } |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 107 | const updatePromises = Array.from(this._pins, pin => pin.updatePreview()); |
| 108 | return Promise.all(updatePromises).then(this._updatedForTest.bind(this)); |
| 109 | } |
| 110 | |
| 111 | _updatedForTest() { |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 112 | } |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 113 | } |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 114 | |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 115 | /** |
| 116 | * @unrestricted |
| 117 | */ |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 118 | export class ConsolePin extends Common.ObjectWrapper.ObjectWrapper { |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 119 | /** |
| 120 | * @param {string} expression |
Tim van der Lippe | eaacb72 | 2020-01-10 12:16:00 | [diff] [blame] | 121 | * @param {!ConsolePinPane} pinPane |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 122 | */ |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 123 | constructor(expression, pinPane) { |
| 124 | super(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 125 | const deletePinIcon = UI.Icon.Icon.create('smallicon-cross', 'console-delete-pin'); |
Michael Liao | 5be6234 | 2019-10-22 23:24:29 | [diff] [blame] | 126 | self.onInvokeElement(deletePinIcon, event => { |
| 127 | pinPane._removePin(this); |
| 128 | event.consume(true); |
| 129 | }); |
John Emau | 53d6409 | 2019-05-31 22:41:56 | [diff] [blame] | 130 | deletePinIcon.tabIndex = 0; |
| 131 | UI.ARIAUtils.setAccessibleName(deletePinIcon, ls`Remove expression`); |
| 132 | UI.ARIAUtils.markAsButton(deletePinIcon); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 133 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 134 | const fragment = UI.Fragment.Fragment.build` |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 135 | <div class='console-pin'> |
| 136 | ${deletePinIcon} |
| 137 | <div class='console-pin-name' $='name'></div> |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 138 | <div class='console-pin-preview' $='preview'>${ls`not available`}</div> |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 139 | </div>`; |
| 140 | this._pinElement = fragment.element(); |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 141 | this._pinPreview = fragment.$('preview'); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 142 | const nameElement = fragment.$('name'); |
| 143 | nameElement.title = expression; |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 144 | this._pinElement[_PinSymbol] = this; |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 145 | |
Erik Luo | 9f24d20 | 2018-09-10 08:51:51 | [diff] [blame] | 146 | /** @type {?SDK.RuntimeModel.EvaluationResult} */ |
| 147 | this._lastResult = null; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 148 | /** @type {?SDK.RuntimeModel.ExecutionContext} */ |
Erik Luo | 9f24d20 | 2018-09-10 08:51:51 | [diff] [blame] | 149 | this._lastExecutionContext = null; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 150 | /** @type {?UI.TextEditor.TextEditor} */ |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 151 | this._editor = null; |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 152 | this._committedExpression = expression; |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 153 | this._hovered = false; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 154 | /** @type {?SDK.RemoteObject.RemoteObject} */ |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 155 | this._lastNode = null; |
| 156 | |
| 157 | this._pinPreview.addEventListener('mouseenter', this.setHovered.bind(this, true), false); |
| 158 | this._pinPreview.addEventListener('mouseleave', this.setHovered.bind(this, false), false); |
| 159 | this._pinPreview.addEventListener('click', event => { |
| 160 | if (this._lastNode) { |
| 161 | Common.Revealer.reveal(this._lastNode); |
| 162 | event.consume(); |
| 163 | } |
| 164 | }, false); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 165 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 166 | this._editorPromise = self.runtime.extension(UI.TextEditor.TextEditorFactory).instance().then(factory => { |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 167 | this._editor = factory.createEditor({ |
John Emau | d3bef01 | 2019-06-05 18:08:40 | [diff] [blame] | 168 | devtoolsAccessibleName: ls`Live expression editor`, |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 169 | lineNumbers: false, |
| 170 | lineWrapping: true, |
| 171 | mimeType: 'javascript', |
| 172 | autoHeight: true, |
| 173 | placeholder: ls`Expression` |
| 174 | }); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 175 | this._editor.configureAutocomplete( |
| 176 | ObjectUI.JavaScriptAutocomplete.JavaScriptAutocompleteConfig.createConfigForEditor(this._editor)); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 177 | this._editor.widget().show(nameElement); |
| 178 | this._editor.widget().element.classList.add('console-pin-editor'); |
| 179 | this._editor.widget().element.tabIndex = -1; |
| 180 | this._editor.setText(expression); |
| 181 | this._editor.widget().element.addEventListener('keydown', event => { |
Erik Luo | 34a22cf | 2018-09-20 02:29:30 | [diff] [blame] | 182 | if (event.key === 'Tab' && !this._editor.text()) { |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 183 | event.consume(); |
Erik Luo | 34a22cf | 2018-09-20 02:29:30 | [diff] [blame] | 184 | return; |
| 185 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 186 | if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code) { |
Erik Luo | 34a22cf | 2018-09-20 02:29:30 | [diff] [blame] | 187 | this._editor.setText(this._committedExpression); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 188 | } |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 189 | }, true); |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 190 | this._editor.widget().element.addEventListener('focusout', event => { |
| 191 | const text = this._editor.text(); |
| 192 | const trimmedText = text.trim(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 193 | if (text.length !== trimmedText.length) { |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 194 | this._editor.setText(trimmedText); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 195 | } |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 196 | this._committedExpression = trimmedText; |
| 197 | pinPane._savePins(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 198 | this._editor.setSelection(TextUtils.TextRange.TextRange.createFromLocation(Infinity, Infinity)); |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 199 | }); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 200 | }); |
| 201 | } |
| 202 | |
| 203 | /** |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 204 | * @param {boolean} hovered |
| 205 | */ |
| 206 | setHovered(hovered) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 207 | if (this._hovered === hovered) { |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 208 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 209 | } |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 210 | this._hovered = hovered; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 211 | if (!hovered && this._lastNode) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 212 | SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 213 | } |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 217 | * @return {string} |
| 218 | */ |
| 219 | expression() { |
| 220 | return this._committedExpression; |
| 221 | } |
| 222 | |
| 223 | /** |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 224 | * @return {!Element} |
| 225 | */ |
| 226 | element() { |
| 227 | return this._pinElement; |
| 228 | } |
| 229 | |
| 230 | async focus() { |
| 231 | await this._editorPromise; |
| 232 | this._editor.widget().focus(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 233 | this._editor.setSelection(TextUtils.TextRange.TextRange.createFromLocation(Infinity, Infinity)); |
Erik Luo | 6294d3b | 2018-07-12 21:54:16 | [diff] [blame] | 234 | } |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 235 | |
| 236 | /** |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 237 | * @param {!UI.ContextMenu.ContextMenu} contextMenu |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 238 | */ |
| 239 | appendToContextMenu(contextMenu) { |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 240 | if (this._lastResult && this._lastResult.object) { |
Erik Luo | 9f24d20 | 2018-09-10 08:51:51 | [diff] [blame] | 241 | contextMenu.appendApplicableItems(this._lastResult.object); |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 242 | // Prevent result from being released manually. It will release along with 'console' group. |
| 243 | this._lastResult = null; |
| 244 | } |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @return {!Promise} |
| 249 | */ |
| 250 | async updatePreview() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 251 | if (!this._editor) { |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 252 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 253 | } |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 254 | const text = this._editor.textWithCurrentSuggestion().trim(); |
| 255 | const isEditing = this._pinElement.hasFocus(); |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 256 | const throwOnSideEffect = isEditing && text !== this._committedExpression; |
| 257 | const timeout = throwOnSideEffect ? 250 : undefined; |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 258 | const executionContext = self.UI.context.flavor(SDK.RuntimeModel.ExecutionContext); |
| 259 | const {preview, result} = await ObjectUI.JavaScriptREPL.JavaScriptREPL.evaluateAndBuildPreview( |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 260 | text, throwOnSideEffect, timeout, !isEditing /* allowErrors */, 'console'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 261 | if (this._lastResult && this._lastExecutionContext) { |
Erik Luo | 9f24d20 | 2018-09-10 08:51:51 | [diff] [blame] | 262 | this._lastExecutionContext.runtimeModel.releaseEvaluationResult(this._lastResult); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 263 | } |
Erik Luo | 9f24d20 | 2018-09-10 08:51:51 | [diff] [blame] | 264 | this._lastResult = result || null; |
Erik Luo | 824d9c2 | 2018-10-10 00:09:25 | [diff] [blame] | 265 | this._lastExecutionContext = executionContext || null; |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 266 | |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 267 | const previewText = preview.deepTextContent(); |
| 268 | if (!previewText || previewText !== this._pinPreview.deepTextContent()) { |
| 269 | this._pinPreview.removeChildren(); |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 270 | if (result && SDK.RuntimeModel.RuntimeModel.isSideEffectFailure(result)) { |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 271 | const sideEffectLabel = this._pinPreview.createChild('span', 'object-value-calculate-value-button'); |
Mathias Bynens | 23ee1aa | 2020-03-02 12:06:38 | [diff] [blame] | 272 | sideEffectLabel.textContent = '(…)'; |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 273 | sideEffectLabel.title = ls`Evaluate, allowing side effects`; |
| 274 | } else if (previewText) { |
| 275 | this._pinPreview.appendChild(preview); |
| 276 | } else if (!isEditing) { |
| 277 | this._pinPreview.createTextChild(ls`not available`); |
| 278 | } |
| 279 | this._pinPreview.title = previewText; |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 280 | } |
Erik Luo | 66bcf10 | 2018-08-25 02:15:37 | [diff] [blame] | 281 | |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 282 | let node = null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 283 | if (result && result.object && result.object.type === 'object' && result.object.subtype === 'node') { |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 284 | node = result.object; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 285 | } |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 286 | if (this._hovered) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 287 | if (node) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 288 | SDK.OverlayModel.OverlayModel.highlightObjectAsDOMNode(node); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 289 | } else if (this._lastNode) { |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 290 | SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 291 | } |
Erik Luo | c75946e | 2018-10-08 21:44:25 | [diff] [blame] | 292 | } |
| 293 | this._lastNode = node || null; |
| 294 | |
Tim van der Lippe | 9b2f871 | 2020-02-12 17:46:22 | [diff] [blame] | 295 | const isError = result && result.exceptionDetails && !SDK.RuntimeModel.RuntimeModel.isSideEffectFailure(result); |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 296 | this._pinElement.classList.toggle('error-level', !!isError); |
Erik Luo | d8eee2b | 2018-07-24 01:36:18 | [diff] [blame] | 297 | } |
Paul Lewis | bf7aa3c | 2019-11-20 17:03:38 | [diff] [blame] | 298 | } |