| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * | 10 * |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 this.setEditable(this._canEditSource()); | 39 this.setEditable(this._canEditSource()); |
| 40 | 40 |
| 41 if (Runtime.experiments.isEnabled('sourceDiff')) | 41 if (Runtime.experiments.isEnabled('sourceDiff')) |
| 42 this._diff = new Sources.SourceCodeDiff(uiSourceCode.requestOriginalConten
t(), this.textEditor); | 42 this._diff = new Sources.SourceCodeDiff(uiSourceCode.requestOriginalConten
t(), this.textEditor); |
| 43 | 43 |
| 44 /** @type {?UI.AutocompleteConfig} */ | 44 /** @type {?UI.AutocompleteConfig} */ |
| 45 this._autocompleteConfig = {isWordChar: Common.TextUtils.isWordChar}; | 45 this._autocompleteConfig = {isWordChar: Common.TextUtils.isWordChar}; |
| 46 Common.moduleSetting('textEditorAutocompletion').addChangeListener(this._upd
ateAutocomplete, this); | 46 Common.moduleSetting('textEditorAutocompletion').addChangeListener(this._upd
ateAutocomplete, this); |
| 47 this._updateAutocomplete(); | 47 this._updateAutocomplete(); |
| 48 | 48 |
| 49 this._rowMessageBuckets = {}; | 49 /** @type {!Map<number, !Sources.UISourceCodeFrame.RowMessageBucket>} */ |
| 50 this._rowMessageBuckets = new Map(); |
| 50 /** @type {!Set<string>} */ | 51 /** @type {!Set<string>} */ |
| 51 this._typeDecorationsPending = new Set(); | 52 this._typeDecorationsPending = new Set(); |
| 52 this._uiSourceCode.addEventListener( | 53 this._uiSourceCode.addEventListener( |
| 53 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha
nged, this); | 54 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha
nged, this); |
| 54 this._uiSourceCode.addEventListener( | 55 this._uiSourceCode.addEventListener( |
| 55 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC
ommitted, this); | 56 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC
ommitted, this); |
| 56 this._uiSourceCode.addEventListener(Workspace.UISourceCode.Events.MessageAdd
ed, this._onMessageAdded, this); | 57 this._uiSourceCode.addEventListener(Workspace.UISourceCode.Events.MessageAdd
ed, this._onMessageAdded, this); |
| 57 this._uiSourceCode.addEventListener(Workspace.UISourceCode.Events.MessageRem
oved, this._onMessageRemoved, this); | 58 this._uiSourceCode.addEventListener(Workspace.UISourceCode.Events.MessageRem
oved, this._onMessageRemoved, this); |
| 58 this._uiSourceCode.addEventListener( | 59 this._uiSourceCode.addEventListener( |
| 59 Workspace.UISourceCode.Events.LineDecorationAdded, this._onLineDecoratio
nAdded, this); | 60 Workspace.UISourceCode.Events.LineDecorationAdded, this._onLineDecoratio
nAdded, this); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 168 |
| 168 /** | 169 /** |
| 169 * @override | 170 * @override |
| 170 * @param {!Common.TextRange} oldRange | 171 * @param {!Common.TextRange} oldRange |
| 171 * @param {!Common.TextRange} newRange | 172 * @param {!Common.TextRange} newRange |
| 172 */ | 173 */ |
| 173 onTextChanged(oldRange, newRange) { | 174 onTextChanged(oldRange, newRange) { |
| 174 if (this._diff) | 175 if (this._diff) |
| 175 this._diff.updateDiffMarkersWhenPossible(); | 176 this._diff.updateDiffMarkersWhenPossible(); |
| 176 super.onTextChanged(oldRange, newRange); | 177 super.onTextChanged(oldRange, newRange); |
| 177 this._clearMessages(); | 178 this._errorPopoverHelper.hidePopover(); |
| 178 if (this._isSettingContent) | 179 if (this._isSettingContent) |
| 179 return; | 180 return; |
| 180 this._muteSourceCodeEvents = true; | 181 this._muteSourceCodeEvents = true; |
| 181 if (this._textEditor.isClean()) | 182 if (this._textEditor.isClean()) |
| 182 this._uiSourceCode.resetWorkingCopy(); | 183 this._uiSourceCode.resetWorkingCopy(); |
| 183 else | 184 else |
| 184 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(this._t
extEditor)); | 185 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(this._t
extEditor)); |
| 185 delete this._muteSourceCodeEvents; | 186 delete this._muteSourceCodeEvents; |
| 186 } | 187 } |
| 187 | 188 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 /** | 305 /** |
| 305 * @param {!Workspace.UISourceCode.Message} message | 306 * @param {!Workspace.UISourceCode.Message} message |
| 306 */ | 307 */ |
| 307 _addMessageToSource(message) { | 308 _addMessageToSource(message) { |
| 308 var lineNumber = message.lineNumber(); | 309 var lineNumber = message.lineNumber(); |
| 309 if (lineNumber >= this._textEditor.linesCount) | 310 if (lineNumber >= this._textEditor.linesCount) |
| 310 lineNumber = this._textEditor.linesCount - 1; | 311 lineNumber = this._textEditor.linesCount - 1; |
| 311 if (lineNumber < 0) | 312 if (lineNumber < 0) |
| 312 lineNumber = 0; | 313 lineNumber = 0; |
| 313 | 314 |
| 314 if (!this._rowMessageBuckets[lineNumber]) { | 315 var messageBucket = this._rowMessageBuckets.get(lineNumber); |
| 315 this._rowMessageBuckets[lineNumber] = | 316 if (!messageBucket) { |
| 316 new Sources.UISourceCodeFrame.RowMessageBucket(this, this._textEditor,
lineNumber); | 317 messageBucket = new Sources.UISourceCodeFrame.RowMessageBucket(this, this.
_textEditor, lineNumber); |
| 318 this._rowMessageBuckets.set(lineNumber, messageBucket); |
| 317 } | 319 } |
| 318 var messageBucket = this._rowMessageBuckets[lineNumber]; | |
| 319 messageBucket.addMessage(message); | 320 messageBucket.addMessage(message); |
| 320 } | 321 } |
| 321 | 322 |
| 322 /** | 323 /** |
| 323 * @param {!Common.Event} event | 324 * @param {!Common.Event} event |
| 324 */ | 325 */ |
| 325 _onMessageRemoved(event) { | 326 _onMessageRemoved(event) { |
| 326 if (!this.loaded) | 327 if (!this.loaded) |
| 327 return; | 328 return; |
| 328 var message = /** @type {!Workspace.UISourceCode.Message} */ (event.data); | 329 var message = /** @type {!Workspace.UISourceCode.Message} */ (event.data); |
| 329 this._removeMessageFromSource(message); | 330 this._removeMessageFromSource(message); |
| 330 } | 331 } |
| 331 | 332 |
| 332 /** | 333 /** |
| 333 * @param {!Workspace.UISourceCode.Message} message | 334 * @param {!Workspace.UISourceCode.Message} message |
| 334 */ | 335 */ |
| 335 _removeMessageFromSource(message) { | 336 _removeMessageFromSource(message) { |
| 336 var lineNumber = message.lineNumber(); | 337 var lineNumber = message.lineNumber(); |
| 337 if (lineNumber >= this._textEditor.linesCount) | 338 if (lineNumber >= this._textEditor.linesCount) |
| 338 lineNumber = this._textEditor.linesCount - 1; | 339 lineNumber = this._textEditor.linesCount - 1; |
| 339 if (lineNumber < 0) | 340 if (lineNumber < 0) |
| 340 lineNumber = 0; | 341 lineNumber = 0; |
| 341 | 342 |
| 342 var messageBucket = this._rowMessageBuckets[lineNumber]; | 343 var messageBucket = this._rowMessageBuckets.get(lineNumber); |
| 343 if (!messageBucket) | 344 if (!messageBucket) |
| 344 return; | 345 return; |
| 345 messageBucket.removeMessage(message); | 346 messageBucket.removeMessage(message); |
| 346 if (!messageBucket.uniqueMessagesCount()) { | 347 if (!messageBucket.uniqueMessagesCount()) { |
| 347 messageBucket.detachFromEditor(); | 348 messageBucket.detachFromEditor(); |
| 348 delete this._rowMessageBuckets[lineNumber]; | 349 this._rowMessageBuckets.delete(lineNumber); |
| 349 } | 350 } |
| 350 } | 351 } |
| 351 | 352 |
| 352 _clearMessages() { | |
| 353 for (var line in this._rowMessageBuckets) { | |
| 354 var bubble = this._rowMessageBuckets[line]; | |
| 355 bubble.detachFromEditor(); | |
| 356 } | |
| 357 | |
| 358 this._rowMessageBuckets = {}; | |
| 359 this._errorPopoverHelper.hidePopover(); | |
| 360 this._uiSourceCode.removeAllMessages(); | |
| 361 } | |
| 362 | |
| 363 /** | 353 /** |
| 364 * @param {!Element} target | 354 * @param {!Element} target |
| 365 * @param {!Event} event | 355 * @param {!Event} event |
| 366 * @return {(!Element|undefined)} | 356 * @return {(!Element|undefined)} |
| 367 */ | 357 */ |
| 368 _getErrorAnchor(target, event) { | 358 _getErrorAnchor(target, event) { |
| 369 var element = target.enclosingNodeOrSelfWithClass('text-editor-line-decorati
on-icon') || | 359 var element = target.enclosingNodeOrSelfWithClass('text-editor-line-decorati
on-icon') || |
| 370 target.enclosingNodeOrSelfWithClass('text-editor-line-decoration-wave'); | 360 target.enclosingNodeOrSelfWithClass('text-editor-line-decoration-wave'); |
| 371 if (!element) | 361 if (!element) |
| 372 return; | 362 return; |
| 373 this._errorWavePopoverAnchor = new AnchorBox(event.clientX, event.clientY, 1
, 1); | 363 this._errorWavePopoverAnchor = new AnchorBox(event.clientX, event.clientY, 1
, 1); |
| 374 return element; | 364 return element; |
| 375 } | 365 } |
| 376 | 366 |
| 377 /** | 367 /** |
| 378 * @param {!Element} anchor | 368 * @param {!Element} anchor |
| 379 * @param {!UI.Popover} popover | 369 * @param {!UI.Popover} popover |
| 380 */ | 370 */ |
| 381 _showErrorPopover(anchor, popover) { | 371 _showErrorPopover(anchor, popover) { |
| 382 var messageBucket = anchor.enclosingNodeOrSelfWithClass('text-editor-line-de
coration')._messageBucket; | 372 var messageBucket = anchor.enclosingNodeOrSelfWithClass('text-editor-line-de
coration')._messageBucket; |
| 383 var messagesOutline = messageBucket.messagesDescription(); | 373 var messagesOutline = messageBucket.messagesDescription(); |
| 384 var popoverAnchor = | 374 var popoverAnchor = |
| 385 anchor.enclosingNodeOrSelfWithClass('text-editor-line-decoration-icon')
? anchor : this._errorWavePopoverAnchor; | 375 anchor.enclosingNodeOrSelfWithClass('text-editor-line-decoration-icon')
? anchor : this._errorWavePopoverAnchor; |
| 386 popover.showForAnchor(messagesOutline, popoverAnchor); | 376 popover.showForAnchor(messagesOutline, popoverAnchor); |
| 387 } | 377 } |
| 388 | 378 |
| 389 _updateBucketDecorations() { | 379 _updateBucketDecorations() { |
| 390 for (var line in this._rowMessageBuckets) { | 380 for (var bucket of this._rowMessageBuckets.values()) |
| 391 var bucket = this._rowMessageBuckets[line]; | |
| 392 bucket._updateDecoration(); | 381 bucket._updateDecoration(); |
| 393 } | |
| 394 } | 382 } |
| 395 | 383 |
| 396 /** | 384 /** |
| 397 * @param {!Common.Event} event | 385 * @param {!Common.Event} event |
| 398 */ | 386 */ |
| 399 _onLineDecorationAdded(event) { | 387 _onLineDecorationAdded(event) { |
| 400 var marker = /** @type {!Workspace.UISourceCode.LineMarker} */ (event.data); | 388 var marker = /** @type {!Workspace.UISourceCode.LineMarker} */ (event.data); |
| 401 this._decorateTypeThrottled(marker.type()); | 389 this._decorateTypeThrottled(marker.type()); |
| 402 } | 390 } |
| 403 | 391 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 641 |
| 654 /** | 642 /** |
| 655 * @param {!Workspace.UISourceCode.Message} a | 643 * @param {!Workspace.UISourceCode.Message} a |
| 656 * @param {!Workspace.UISourceCode.Message} b | 644 * @param {!Workspace.UISourceCode.Message} b |
| 657 * @return {number} | 645 * @return {number} |
| 658 */ | 646 */ |
| 659 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) { | 647 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) { |
| 660 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] - | 648 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] - |
| 661 Workspace.UISourceCode.Message._messageLevelPriority[b.level()]; | 649 Workspace.UISourceCode.Message._messageLevelPriority[b.level()]; |
| 662 }; | 650 }; |
| OLD | NEW |