OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 |
4 /** | 5 /** |
5 * @implements {Bindings.DebuggerSourceMapping} | 6 * @implements {Bindings.DebuggerSourceMapping} |
6 * @unrestricted | |
7 */ | 7 */ |
8 Sources.FormatterScriptMapping = class { | 8 Sources.FormatterScriptMapping = class { |
9 /** | 9 /** |
10 * @param {!SDK.DebuggerModel} debuggerModel | |
11 * @param {!Sources.ScriptFormatterEditorAction} editorAction | |
12 */ | |
13 constructor(debuggerModel, editorAction) { | |
14 this._debuggerModel = debuggerModel; | |
15 this._editorAction = editorAction; | |
16 } | |
17 | |
18 /** | |
19 * @override | 10 * @override |
20 * @param {!SDK.DebuggerModel.Location} rawLocation | 11 * @param {!SDK.DebuggerModel.Location} rawLocation |
21 * @return {?Workspace.UILocation} | 12 * @return {?Workspace.UILocation} |
22 */ | 13 */ |
23 rawLocationToUILocation(rawLocation) { | 14 rawLocationToUILocation(rawLocation) { |
24 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL
ocation); | 15 var script = rawLocation.script(); |
25 var script = debuggerModelLocation.script(); | 16 var formatData = script && Sources.SourceFormatData._for(script); |
26 if (!script) | |
27 return null; | |
28 var uiSourceCode = this._editorAction._uiSourceCodes.get(script); | |
29 if (!uiSourceCode) | |
30 return null; | |
31 | |
32 var formatData = this._editorAction._formatData.get(uiSourceCode); | |
33 if (!formatData) | 17 if (!formatData) |
34 return null; | 18 return null; |
35 var mapping = formatData.mapping; | 19 var lineNumber = rawLocation.lineNumber; |
36 var lineNumber = debuggerModelLocation.lineNumber; | 20 var columnNumber = rawLocation.columnNumber || 0; |
37 var columnNumber = debuggerModelLocation.columnNumber || 0; | 21 var formattedLocation = formatData.mapping.originalToFormatted(lineNumber, c
olumnNumber); |
38 var formattedLocation = mapping.originalToFormatted(lineNumber, columnNumber
); | 22 return formatData.formattedSourceCode.uiLocation(formattedLocation[0], forma
ttedLocation[1]); |
39 return uiSourceCode.uiLocation(formattedLocation[0], formattedLocation[1]); | |
40 } | 23 } |
41 | 24 |
42 /** | 25 /** |
43 * @override | 26 * @override |
44 * @param {!Workspace.UISourceCode} uiSourceCode | 27 * @param {!Workspace.UISourceCode} uiSourceCode |
45 * @param {number} lineNumber | 28 * @param {number} lineNumber |
46 * @param {number} columnNumber | 29 * @param {number} columnNumber |
47 * @return {?SDK.DebuggerModel.Location} | 30 * @return {?SDK.DebuggerModel.Location} |
48 */ | 31 */ |
49 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { | 32 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
50 var formatData = this._editorAction._formatData.get(uiSourceCode); | 33 var formatData = Sources.SourceFormatData._for(uiSourceCode); |
51 if (!formatData) | 34 if (!formatData) |
52 return null; | 35 return null; |
53 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber, co
lumnNumber); | 36 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber, co
lumnNumber); |
54 for (var i = 0; i < formatData.scripts.length; ++i) { | 37 var scripts = Sources.ScriptFormatterEditorAction._scriptsForUISourceCode(fo
rmatData.originalSourceCode); |
55 if (formatData.scripts[i].debuggerModel === this._debuggerModel) | 38 if (!scripts.length) |
56 return this._debuggerModel.createRawLocation(formatData.scripts[i], orig
inalLocation[0], originalLocation[1]); | 39 return null; |
57 } | 40 return scripts[0].debuggerModel.createRawLocation(scripts[0], originalLocati
on[0], originalLocation[1]); |
58 return null; | |
59 } | 41 } |
60 | 42 |
61 /** | 43 /** |
62 * @override | 44 * @override |
63 * @return {boolean} | 45 * @return {boolean} |
64 */ | 46 */ |
65 isIdentity() { | 47 isIdentity() { |
66 return false; | 48 return false; |
67 } | 49 } |
68 | 50 |
69 /** | 51 /** |
70 * @override | 52 * @override |
71 * @param {!Workspace.UISourceCode} uiSourceCode | 53 * @param {!Workspace.UISourceCode} uiSourceCode |
72 * @param {number} lineNumber | 54 * @param {number} lineNumber |
73 * @return {boolean} | 55 * @return {boolean} |
74 */ | 56 */ |
75 uiLineHasMapping(uiSourceCode, lineNumber) { | 57 uiLineHasMapping(uiSourceCode, lineNumber) { |
76 return true; | 58 return true; |
77 } | 59 } |
78 }; | 60 }; |
79 | 61 |
80 /** | 62 Sources.SourceFormatData = class { |
81 * @unrestricted | |
82 */ | |
83 Sources.FormatterScriptMapping.FormatData = class { | |
84 /** | 63 /** |
85 * @param {string} projectId | 64 * @param {!Workspace.UISourceCode} originalSourceCode |
86 * @param {string} path | 65 * @param {!Workspace.UISourceCode} formattedSourceCode |
87 * @param {!Sources.FormatterSourceMapping} mapping | 66 * @param {!Sources.FormatterSourceMapping} mapping |
88 * @param {!Array.<!SDK.Script>} scripts | |
89 */ | 67 */ |
90 constructor(projectId, path, mapping, scripts) { | 68 constructor(originalSourceCode, formattedSourceCode, mapping) { |
91 this.projectId = projectId; | 69 this.originalSourceCode = originalSourceCode; |
92 this.path = path; | 70 this.formattedSourceCode = formattedSourceCode; |
93 this.mapping = mapping; | 71 this.mapping = mapping; |
94 this.scripts = scripts; | 72 } |
| 73 |
| 74 originalPath() { |
| 75 return this.originalSourceCode.project().id() + ':' + this.originalSourceCod
e.url(); |
| 76 } |
| 77 |
| 78 /** |
| 79 * @param {!Object} object |
| 80 * @return {?Sources.SourceFormatData} |
| 81 */ |
| 82 static _for(object) { |
| 83 return object[Sources.SourceFormatData._formatDataSymbol]; |
95 } | 84 } |
96 }; | 85 }; |
97 | 86 |
| 87 Sources.SourceFormatData._formatDataSymbol = Symbol('formatData'); |
| 88 |
98 /** | 89 /** |
99 * @implements {Sources.SourcesView.EditorAction} | 90 * @implements {Sources.SourcesView.EditorAction} |
100 * @implements {SDK.SDKModelObserver<!SDK.DebuggerModel>} | |
101 * @unrestricted | 91 * @unrestricted |
102 */ | 92 */ |
103 Sources.ScriptFormatterEditorAction = class { | 93 Sources.ScriptFormatterEditorAction = class { |
104 constructor() { | 94 constructor() { |
105 this._projectId = 'formatter:'; | 95 this._projectId = 'formatter:'; |
106 this._project = new Bindings.ContentProviderBasedProject( | 96 this._project = new Bindings.ContentProviderBasedProject( |
107 Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter,
'formatter', | 97 Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter,
'formatter', |
108 true /* isServiceProject */); | 98 true /* isServiceProject */); |
109 | 99 |
110 /** @type {!Map.<!SDK.Script, !Workspace.UISourceCode>} */ | 100 /** @type {!Map<string, !Workspace.UISourceCode>} */ |
111 this._uiSourceCodes = new Map(); | |
112 /** @type {!Map.<string, string>} */ | |
113 this._formattedPaths = new Map(); | 101 this._formattedPaths = new Map(); |
114 /** @type {!Map.<!Workspace.UISourceCode, !Sources.FormatterScriptMapping.Fo
rmatData>} */ | 102 /** @type {!Set<string>} */ |
115 this._formatData = new Map(); | |
116 | |
117 /** @type {!Set.<string>} */ | |
118 this._pathsToFormatOnLoad = new Set(); | 103 this._pathsToFormatOnLoad = new Set(); |
119 | 104 this._scriptMapping = new Sources.FormatterScriptMapping(); |
120 /** @type {!Map.<!SDK.DebuggerModel, !Sources.FormatterScriptMapping>} */ | 105 Workspace.workspace.addEventListener( |
121 this._scriptMappingByDebuggerModel = new Map(); | 106 Workspace.Workspace.Events.UISourceCodeRemoved, this._onUISourceCodeRemo
ved, this); |
122 this._workspace = Workspace.workspace; | |
123 SDK.targetManager.observeModels(SDK.DebuggerModel, this); | |
124 } | 107 } |
125 | 108 |
126 /** | 109 /** |
127 * @override | 110 * @param {!Common.Event} event |
128 * @param {!SDK.DebuggerModel} debuggerModel | |
129 */ | 111 */ |
130 modelAdded(debuggerModel) { | 112 _onUISourceCodeRemoved(event) { |
131 this._scriptMappingByDebuggerModel.set(debuggerModel, new Sources.FormatterS
criptMapping(debuggerModel, this)); | 113 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
132 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleared,
this._debuggerReset, this); | 114 var formattedUISourceCode = this._formattedPaths.get(uiSourceCode.project().
id() + ':' + uiSourceCode.url()); |
| 115 if (formattedUISourceCode) |
| 116 this._discardFormattedUISourceCodeScript(formattedUISourceCode, false); |
133 } | 117 } |
134 | 118 |
135 /** | 119 /** |
136 * @override | |
137 * @param {!SDK.DebuggerModel} debuggerModel | |
138 */ | |
139 modelRemoved(debuggerModel) { | |
140 this._scriptMappingByDebuggerModel.remove(debuggerModel); | |
141 this._cleanForModel(debuggerModel); | |
142 debuggerModel.removeEventListener(SDK.DebuggerModel.Events.GlobalObjectClear
ed, this._debuggerReset, this); | |
143 } | |
144 | |
145 /** | |
146 * @param {!Common.Event} event | 120 * @param {!Common.Event} event |
147 */ | 121 */ |
148 _editorSelected(event) { | 122 _editorSelected(event) { |
149 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | 123 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
150 this._updateButton(uiSourceCode); | 124 this._updateButton(uiSourceCode); |
151 | 125 |
152 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); | 126 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); |
153 if (this._isFormatableScript(uiSourceCode) && this._pathsToFormatOnLoad.has(
path) && | 127 if (this._isFormatableScript(uiSourceCode) && this._pathsToFormatOnLoad.has(
path) && |
154 !this._formattedPaths.get(path)) | 128 !this._formattedPaths.get(path)) |
155 this._formatUISourceCodeScript(uiSourceCode); | 129 this._formatUISourceCodeScript(uiSourceCode); |
156 } | 130 } |
157 | 131 |
158 /** | 132 /** |
159 * @param {!Common.Event} event | 133 * @param {!Common.Event} event |
160 */ | 134 */ |
161 _editorClosed(event) { | 135 _editorClosed(event) { |
162 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data.uiSour
ceCode); | 136 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data.uiSour
ceCode); |
163 var wasSelected = /** @type {boolean} */ (event.data.wasSelected); | 137 var wasSelected = /** @type {boolean} */ (event.data.wasSelected); |
164 | 138 |
165 if (wasSelected) | 139 if (wasSelected) |
166 this._updateButton(null); | 140 this._updateButton(null); |
167 this._discardFormattedUISourceCodeScript(uiSourceCode); | 141 this._discardFormattedUISourceCodeScript(uiSourceCode, true); |
168 } | 142 } |
169 | 143 |
170 /** | 144 /** |
171 * @param {?Workspace.UISourceCode} uiSourceCode | 145 * @param {?Workspace.UISourceCode} uiSourceCode |
172 */ | 146 */ |
173 _updateButton(uiSourceCode) { | 147 _updateButton(uiSourceCode) { |
174 this._button.element.classList.toggle('hidden', !this._isFormatableScript(ui
SourceCode)); | 148 this._button.element.classList.toggle('hidden', !this._isFormatableScript(ui
SourceCode)); |
175 } | 149 } |
176 | 150 |
177 /** | 151 /** |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 if (sourceFrame) { | 207 if (sourceFrame) { |
234 var selection = sourceFrame.selection(); | 208 var selection = sourceFrame.selection(); |
235 start = mapping.originalToFormatted(selection.startLine, selection.startCo
lumn); | 209 start = mapping.originalToFormatted(selection.startLine, selection.startCo
lumn); |
236 } | 210 } |
237 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], start[
1]); | 211 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], start[
1]); |
238 this._updateButton(formattedUISourceCode); | 212 this._updateButton(formattedUISourceCode); |
239 } | 213 } |
240 | 214 |
241 /** | 215 /** |
242 * @param {!Workspace.UISourceCode} formattedUISourceCode | 216 * @param {!Workspace.UISourceCode} formattedUISourceCode |
| 217 * @param {boolean} userAction |
243 */ | 218 */ |
244 _discardFormattedUISourceCodeScript(formattedUISourceCode) { | 219 _discardFormattedUISourceCodeScript(formattedUISourceCode, userAction) { |
245 var formatData = this._formatData.get(formattedUISourceCode); | 220 var formatData = Sources.SourceFormatData._for(formattedUISourceCode); |
246 if (!formatData) | 221 if (!formatData) |
247 return; | 222 return; |
248 | 223 |
249 this._formatData.remove(formattedUISourceCode); | 224 var path = formatData.originalPath(); |
250 var path = formatData.projectId + ':' + formatData.path; | |
251 this._formattedPaths.remove(path); | 225 this._formattedPaths.remove(path); |
252 this._pathsToFormatOnLoad.delete(path); | 226 delete formattedUISourceCode[Sources.SourceFormatData._formatDataSymbol]; |
253 for (var i = 0; i < formatData.scripts.length; ++i) { | 227 if (userAction) |
254 this._uiSourceCodes.remove(formatData.scripts[i]); | 228 this._pathsToFormatOnLoad.delete(path); |
255 Bindings.debuggerWorkspaceBinding.popSourceMapping(formatData.scripts[i]); | 229 var scripts = Sources.ScriptFormatterEditorAction._scriptsForUISourceCode(fo
rmatData.originalSourceCode); |
| 230 for (var script of scripts) { |
| 231 delete script[Sources.SourceFormatData._formatDataSymbol]; |
| 232 Bindings.debuggerWorkspaceBinding.popSourceMapping(script); |
256 } | 233 } |
| 234 if (scripts[0]) |
| 235 Bindings.debuggerWorkspaceBinding.setSourceMapping(scripts[0].debuggerMode
l, formattedUISourceCode, null); |
257 this._project.removeFile(formattedUISourceCode.url()); | 236 this._project.removeFile(formattedUISourceCode.url()); |
258 } | 237 } |
259 | 238 |
260 /** | 239 /** |
261 * @param {!SDK.DebuggerModel} debuggerModel | 240 * @param {!Workspace.UISourceCode} uiSourceCode |
| 241 * @return {!Array<!SDK.Script>} |
262 */ | 242 */ |
263 _cleanForModel(debuggerModel) { | 243 static _scriptsForUISourceCode(uiSourceCode) { |
264 var uiSourceCodes = this._formatData.keysArray(); | 244 if (uiSourceCode.contentType() === Common.resourceTypes.Document) { |
265 for (var i = 0; i < uiSourceCodes.length; ++i) { | 245 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
266 Bindings.debuggerWorkspaceBinding.setSourceMapping(debuggerModel, uiSource
Codes[i], null); | 246 var debuggerModel = target && target.model(SDK.DebuggerModel); |
267 var formatData = this._formatData.get(uiSourceCodes[i]); | 247 if (debuggerModel) { |
268 var scripts = []; | 248 var scripts = debuggerModel.scriptsForSourceURL(uiSourceCode.url()) |
269 for (var j = 0; j < formatData.scripts.length; ++j) { | 249 .filter(script => script.isInlineScript() && !script.h
asSourceURL); |
270 if (formatData.scripts[j].debuggerModel === debuggerModel) | 250 return scripts; |
271 this._uiSourceCodes.remove(formatData.scripts[j]); | |
272 else | |
273 scripts.push(formatData.scripts[j]); | |
274 } | 251 } |
275 | |
276 if (scripts.length) { | |
277 formatData.scripts = scripts; | |
278 } else { | |
279 this._formattedPaths.remove(formatData.projectId + ':' + formatData.path
); | |
280 this._formatData.remove(uiSourceCodes[i]); | |
281 this._project.removeFile(uiSourceCodes[i].url()); | |
282 } | |
283 } | |
284 } | |
285 | |
286 /** | |
287 * @param {!Common.Event} event | |
288 */ | |
289 _debuggerReset(event) { | |
290 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); | |
291 this._cleanForModel(debuggerModel); | |
292 } | |
293 | |
294 /** | |
295 * @param {!Workspace.UISourceCode} uiSourceCode | |
296 * @return {!Array.<!SDK.Script>} | |
297 */ | |
298 _scriptsForUISourceCode(uiSourceCode) { | |
299 /** | |
300 * @param {!SDK.Script} script | |
301 * @return {boolean} | |
302 */ | |
303 function isInlineScript(script) { | |
304 return script.isInlineScript() && !script.hasSourceURL; | |
305 } | |
306 | |
307 if (uiSourceCode.contentType() === Common.resourceTypes.Document) { | |
308 var scripts = []; | |
309 var debuggerModels = SDK.targetManager.models(SDK.DebuggerModel); | |
310 for (var i = 0; i < debuggerModels.length; ++i) | |
311 scripts.pushAll(debuggerModels[i].scriptsForSourceURL(uiSourceCode.url()
)); | |
312 return scripts.filter(isInlineScript); | |
313 } | 252 } |
314 if (uiSourceCode.contentType().isScript()) { | 253 if (uiSourceCode.contentType().isScript()) { |
315 var rawLocation = Bindings.debuggerWorkspaceBinding.uiLocationToRawLocatio
n(uiSourceCode, 0, 0); | 254 var rawLocation = Bindings.debuggerWorkspaceBinding.uiLocationToRawLocatio
n(uiSourceCode, 0, 0); |
316 if (rawLocation) | 255 if (rawLocation) |
317 return [rawLocation.script()]; | 256 return [rawLocation.script()]; |
318 } | 257 } |
319 return []; | 258 return []; |
320 } | 259 } |
321 | 260 |
322 /** | 261 /** |
323 * @param {!Workspace.UISourceCode} uiSourceCode | 262 * @param {!Workspace.UISourceCode} uiSourceCode |
324 */ | 263 */ |
325 _formatUISourceCodeScript(uiSourceCode) { | 264 _formatUISourceCodeScript(uiSourceCode) { |
326 var formattedPath = this._formattedPaths.get(uiSourceCode.project().id() + '
:' + uiSourceCode.url()); | 265 var formattedUISourceCode = this._formattedPaths.get(uiSourceCode.project().
id() + ':' + uiSourceCode.url()); |
327 if (formattedPath) { | 266 if (formattedUISourceCode) { |
328 var uiSourceCodePath = formattedPath; | 267 var formatData = Sources.SourceFormatData._for(formattedUISourceCode); |
329 var formattedUISourceCode = this._workspace.uiSourceCode(this._projectId,
uiSourceCodePath); | |
330 var formatData = formattedUISourceCode ? this._formatData.get(formattedUIS
ourceCode) : null; | |
331 if (formatData) { | 268 if (formatData) { |
332 this._showIfNeeded( | 269 this._showIfNeeded( |
333 uiSourceCode, /** @type {!Workspace.UISourceCode} */ (formattedUISou
rceCode), formatData.mapping); | 270 uiSourceCode, /** @type {!Workspace.UISourceCode} */ (formattedUISou
rceCode), formatData.mapping); |
| 271 return; |
334 } | 272 } |
335 return; | |
336 } | 273 } |
337 | 274 |
338 uiSourceCode.requestContent().then(contentLoaded.bind(this)); | 275 uiSourceCode.requestContent().then(contentLoaded.bind(this)); |
339 | 276 |
340 /** | 277 /** |
341 * @this {Sources.ScriptFormatterEditorAction} | 278 * @this {Sources.ScriptFormatterEditorAction} |
342 * @param {?string} content | 279 * @param {?string} content |
343 */ | 280 */ |
344 function contentLoaded(content) { | 281 function contentLoaded(content) { |
345 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourc
eCode); | 282 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourc
eCode); |
346 Sources.Formatter.format(uiSourceCode.contentType(), highlighterType, cont
ent || '', innerCallback.bind(this)); | 283 Sources.Formatter.format(uiSourceCode.contentType(), highlighterType, cont
ent || '', innerCallback.bind(this)); |
347 } | 284 } |
348 | 285 |
349 /** | 286 /** |
350 * @this {Sources.ScriptFormatterEditorAction} | 287 * @this {Sources.ScriptFormatterEditorAction} |
351 * @param {string} formattedContent | 288 * @param {string} formattedContent |
352 * @param {!Sources.FormatterSourceMapping} formatterMapping | 289 * @param {!Sources.FormatterSourceMapping} formatterMapping |
353 */ | 290 */ |
354 function innerCallback(formattedContent, formatterMapping) { | 291 function innerCallback(formattedContent, formatterMapping) { |
355 var scripts = this._scriptsForUISourceCode(uiSourceCode); | |
356 var formattedURL = uiSourceCode.url() + ':formatted'; | 292 var formattedURL = uiSourceCode.url() + ':formatted'; |
357 var contentProvider = | 293 var contentProvider = |
358 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con
tentType(), formattedContent); | 294 Common.StaticContentProvider.fromString(formattedURL, uiSourceCode.con
tentType(), formattedContent); |
359 var formattedUISourceCode = this._project.addContentProvider(formattedURL,
contentProvider); | 295 var formattedUISourceCode = this._project.addContentProvider(formattedURL,
contentProvider); |
360 var formattedPath = formattedUISourceCode.url(); | 296 var formatData = new Sources.SourceFormatData(uiSourceCode, formattedUISou
rceCode, formatterMapping); |
361 var formatData = new Sources.FormatterScriptMapping.FormatData( | 297 formattedUISourceCode[Sources.SourceFormatData._formatDataSymbol] = format
Data; |
362 uiSourceCode.project().id(), uiSourceCode.url(), formatterMapping, scr
ipts); | 298 |
363 this._formatData.set(formattedUISourceCode, formatData); | 299 var path = formatData.originalPath(); |
364 var path = uiSourceCode.project().id() + ':' + uiSourceCode.url(); | 300 this._formattedPaths.set(path, formattedUISourceCode); |
365 this._formattedPaths.set(path, formattedPath); | |
366 this._pathsToFormatOnLoad.add(path); | 301 this._pathsToFormatOnLoad.add(path); |
367 for (var i = 0; i < scripts.length; ++i) { | 302 |
368 this._uiSourceCodes.set(scripts[i], formattedUISourceCode); | 303 var scripts = Sources.ScriptFormatterEditorAction._scriptsForUISourceCode(
uiSourceCode); |
369 var scriptMapping = | 304 if (!scripts) |
370 /** @type {!Sources.FormatterScriptMapping} */ ( | 305 return; |
371 this._scriptMappingByDebuggerModel.get(scripts[i].debuggerModel)
); | 306 for (var script of scripts) { |
372 Bindings.debuggerWorkspaceBinding.pushSourceMapping(scripts[i], scriptMa
pping); | 307 script[Sources.SourceFormatData._formatDataSymbol] = formatData; |
| 308 Bindings.debuggerWorkspaceBinding.pushSourceMapping(script, this._script
Mapping); |
373 } | 309 } |
374 | 310 |
375 var debuggerModels = SDK.targetManager.models(SDK.DebuggerModel); | 311 Bindings.debuggerWorkspaceBinding.setSourceMapping( |
376 for (var i = 0; i < debuggerModels.length; ++i) { | 312 scripts[0].debuggerModel, formattedUISourceCode, this._scriptMapping); |
377 var scriptMapping = | |
378 /** @type {!Sources.FormatterScriptMapping} */ (this._scriptMappingB
yDebuggerModel.get(debuggerModels[i])); | |
379 Bindings.debuggerWorkspaceBinding.setSourceMapping(debuggerModels[i], fo
rmattedUISourceCode, scriptMapping); | |
380 } | |
381 | 313 |
382 for (var decoration of uiSourceCode.allDecorations()) { | 314 for (var decoration of uiSourceCode.allDecorations()) { |
383 var range = decoration.range(); | 315 var range = decoration.range(); |
384 var startLocation = formatterMapping.originalToFormatted(range.startLine
, range.startColumn); | 316 var startLocation = formatterMapping.originalToFormatted(range.startLine
, range.startColumn); |
385 var endLocation = formatterMapping.originalToFormatted(range.endLine, ra
nge.endColumn); | 317 var endLocation = formatterMapping.originalToFormatted(range.endLine, ra
nge.endColumn); |
386 | 318 |
387 formattedUISourceCode.addDecoration( | 319 formattedUISourceCode.addDecoration( |
388 new TextUtils.TextRange(startLocation[0], startLocation[1], endLocat
ion[0], endLocation[1]), | 320 new TextUtils.TextRange(startLocation[0], startLocation[1], endLocat
ion[0], endLocation[1]), |
389 /** @type {string} */ (decoration.type()), decoration.data()); | 321 /** @type {string} */ (decoration.type()), decoration.data()); |
390 } | 322 } |
391 | 323 |
392 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMapping); | 324 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMapping); |
393 } | 325 } |
394 } | 326 } |
395 }; | 327 }; |
OLD | NEW |