| 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 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 importScript("cm/markselection.js"); | 39 importScript("cm/markselection.js"); |
| 40 importScript("cm/comment.js"); | 40 importScript("cm/comment.js"); |
| 41 importScript("cm/overlay.js"); | 41 importScript("cm/overlay.js"); |
| 42 | 42 |
| 43 importScript("cm/htmlembedded.js"); | 43 importScript("cm/htmlembedded.js"); |
| 44 importScript("cm/clike.js"); | 44 importScript("cm/clike.js"); |
| 45 importScript("cm/coffeescript.js"); | 45 importScript("cm/coffeescript.js"); |
| 46 importScript("cm/php.js"); | 46 importScript("cm/php.js"); |
| 47 importScript("cm/python.js"); | 47 importScript("cm/python.js"); |
| 48 importScript("cm/shell.js"); | 48 importScript("cm/shell.js"); |
| 49 importScript("CodeMirrorUtils.js"); |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * @constructor | 52 * @constructor |
| 52 * @extends {WebInspector.View} | 53 * @extends {WebInspector.View} |
| 53 * @implements {WebInspector.TextEditor} | 54 * @implements {WebInspector.TextEditor} |
| 54 * @param {?string} url | 55 * @param {?string} url |
| 55 * @param {WebInspector.TextEditorDelegate} delegate | 56 * @param {WebInspector.TextEditorDelegate} delegate |
| 56 */ | 57 */ |
| 57 WebInspector.CodeMirrorTextEditor = function(url, delegate) | 58 WebInspector.CodeMirrorTextEditor = function(url, delegate) |
| 58 { | 59 { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 this.element.style.overflow = "hidden"; | 157 this.element.style.overflow = "hidden"; |
| 157 this.element.firstChild.addStyleClass("source-code"); | 158 this.element.firstChild.addStyleClass("source-code"); |
| 158 this.element.firstChild.addStyleClass("fill"); | 159 this.element.firstChild.addStyleClass("fill"); |
| 159 this._elementToWidget = new Map(); | 160 this._elementToWidget = new Map(); |
| 160 this._nestedUpdatesCounter = 0; | 161 this._nestedUpdatesCounter = 0; |
| 161 | 162 |
| 162 this.element.addEventListener("focus", this._handleElementFocus.bind(this),
false); | 163 this.element.addEventListener("focus", this._handleElementFocus.bind(this),
false); |
| 163 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru
e); | 164 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), tru
e); |
| 164 this.element.tabIndex = 0; | 165 this.element.tabIndex = 0; |
| 165 | 166 |
| 166 this._overrideModeWithPrefixedTokens("css-base", "css-"); | |
| 167 this._overrideModeWithPrefixedTokens("javascript", "js-"); | |
| 168 this._overrideModeWithPrefixedTokens("xml", "xml-"); | |
| 169 | |
| 170 this._setupSelectionColor(); | 167 this._setupSelectionColor(); |
| 171 this._setupWhitespaceHighlight(); | 168 this._setupWhitespaceHighlight(); |
| 172 } | 169 } |
| 173 | 170 |
| 174 WebInspector.CodeMirrorTextEditor.autocompleteCommand = function(codeMirror) | 171 WebInspector.CodeMirrorTextEditor.autocompleteCommand = function(codeMirror) |
| 175 { | 172 { |
| 176 codeMirror._codeMirrorTextEditor._autocompleteController.autocomplete(); | 173 codeMirror._codeMirrorTextEditor._autocompleteController.autocomplete(); |
| 177 } | 174 } |
| 178 CodeMirror.commands.autocomplete = WebInspector.CodeMirrorTextEditor.autocomplet
eCommand; | 175 CodeMirror.commands.autocomplete = WebInspector.CodeMirrorTextEditor.autocomplet
eCommand; |
| 179 | 176 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 if (!element || !element.isSelfOrDescendant(this._codeMirror.getWrapperE
lement())) | 443 if (!element || !element.isSelfOrDescendant(this._codeMirror.getWrapperE
lement())) |
| 447 return null; | 444 return null; |
| 448 var gutterBox = this._codeMirror.getGutterElement().boxInWindow(); | 445 var gutterBox = this._codeMirror.getGutterElement().boxInWindow(); |
| 449 if (x >= gutterBox.x && x <= gutterBox.x + gutterBox.width && | 446 if (x >= gutterBox.x && x <= gutterBox.x + gutterBox.width && |
| 450 y >= gutterBox.y && y <= gutterBox.y + gutterBox.height) | 447 y >= gutterBox.y && y <= gutterBox.y + gutterBox.height) |
| 451 return null; | 448 return null; |
| 452 var coords = this._codeMirror.coordsChar({left: x, top: y}); | 449 var coords = this._codeMirror.coordsChar({left: x, top: y}); |
| 453 return this._toRange(coords, coords); | 450 return this._toRange(coords, coords); |
| 454 }, | 451 }, |
| 455 | 452 |
| 456 _convertTokenType: function(tokenType) | |
| 457 { | |
| 458 if (tokenType.startsWith("js-variable") || tokenType.startsWith("js-prop
erty") || tokenType === "js-def") | |
| 459 return "javascript-ident"; | |
| 460 if (tokenType === "js-string-2") | |
| 461 return "javascript-regexp"; | |
| 462 if (tokenType === "js-number" || tokenType === "js-comment" || tokenType
=== "js-string" || tokenType === "js-keyword") | |
| 463 return "javascript-" + tokenType.substring("js-".length); | |
| 464 return null; | |
| 465 }, | |
| 466 | |
| 467 /** | 453 /** |
| 468 * @param {number} lineNumber | 454 * @param {number} lineNumber |
| 469 * @param {number} column | 455 * @param {number} column |
| 470 * @return {?{startColumn: number, endColumn: number, type: string}} | 456 * @return {?{startColumn: number, endColumn: number, type: string}} |
| 471 */ | 457 */ |
| 472 tokenAtTextPosition: function(lineNumber, column) | 458 tokenAtTextPosition: function(lineNumber, column) |
| 473 { | 459 { |
| 474 if (lineNumber < 0 || lineNumber >= this._codeMirror.lineCount()) | 460 if (lineNumber < 0 || lineNumber >= this._codeMirror.lineCount()) |
| 475 return null; | 461 return null; |
| 476 var token = this._codeMirror.getTokenAt(new CodeMirror.Pos(lineNumber, (
column || 0) + 1)); | 462 var token = this._codeMirror.getTokenAt(new CodeMirror.Pos(lineNumber, (
column || 0) + 1)); |
| 477 if (!token || !token.type) | 463 if (!token || !token.type) |
| 478 return null; | 464 return null; |
| 479 var convertedType = this._convertTokenType(token.type); | 465 var convertedType = WebInspector.CodeMirrorUtils.convertTokenType(token.
type); |
| 480 if (!convertedType) | 466 if (!convertedType) |
| 481 return null; | 467 return null; |
| 482 return { | 468 return { |
| 483 startColumn: token.start, | 469 startColumn: token.start, |
| 484 endColumn: token.end - 1, | 470 endColumn: token.end - 1, |
| 485 type: convertedType | 471 type: convertedType |
| 486 }; | 472 }; |
| 487 }, | 473 }, |
| 488 | 474 |
| 489 /** | 475 /** |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } | 536 } |
| 551 var whitespaceMode = { | 537 var whitespaceMode = { |
| 552 token: nextToken | 538 token: nextToken |
| 553 }; | 539 }; |
| 554 return CodeMirror.overlayMode(CodeMirror.getMode(config, mimeType),
whitespaceMode, false); | 540 return CodeMirror.overlayMode(CodeMirror.getMode(config, mimeType),
whitespaceMode, false); |
| 555 } | 541 } |
| 556 CodeMirror.defineMode(modeName, modeConstructor); | 542 CodeMirror.defineMode(modeName, modeConstructor); |
| 557 return modeName; | 543 return modeName; |
| 558 }, | 544 }, |
| 559 | 545 |
| 560 /** | |
| 561 * @param {string} modeName | |
| 562 * @param {string} tokenPrefix | |
| 563 */ | |
| 564 _overrideModeWithPrefixedTokens: function(modeName, tokenPrefix) | |
| 565 { | |
| 566 var oldModeName = modeName + "-old"; | |
| 567 if (CodeMirror.modes[oldModeName]) | |
| 568 return; | |
| 569 | |
| 570 CodeMirror.defineMode(oldModeName, CodeMirror.modes[modeName]); | |
| 571 CodeMirror.defineMode(modeName, modeConstructor); | |
| 572 | |
| 573 function modeConstructor(config, parserConfig) | |
| 574 { | |
| 575 var innerConfig = {}; | |
| 576 for (var i in parserConfig) | |
| 577 innerConfig[i] = parserConfig[i]; | |
| 578 innerConfig.name = oldModeName; | |
| 579 var codeMirrorMode = CodeMirror.getMode(config, innerConfig); | |
| 580 codeMirrorMode.name = modeName; | |
| 581 codeMirrorMode.token = tokenOverride.bind(this, codeMirrorMode.token
); | |
| 582 return codeMirrorMode; | |
| 583 } | |
| 584 | |
| 585 function tokenOverride(superToken, stream, state) | |
| 586 { | |
| 587 var token = superToken(stream, state); | |
| 588 return token ? tokenPrefix + token : token; | |
| 589 } | |
| 590 }, | |
| 591 | |
| 592 _enableLongLinesMode: function() | 546 _enableLongLinesMode: function() |
| 593 { | 547 { |
| 594 this._codeMirror.setOption("styleSelectedText", false); | 548 this._codeMirror.setOption("styleSelectedText", false); |
| 595 this._longLinesMode = true; | 549 this._longLinesMode = true; |
| 596 }, | 550 }, |
| 597 | 551 |
| 598 _disableLongLinesMode: function() | 552 _disableLongLinesMode: function() |
| 599 { | 553 { |
| 600 this._codeMirror.setOption("styleSelectedText", true); | 554 this._codeMirror.setOption("styleSelectedText", true); |
| 601 this._longLinesMode = false; | 555 this._longLinesMode = false; |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 * @param {number} line | 1515 * @param {number} line |
| 1562 * @param {number} column | 1516 * @param {number} column |
| 1563 * @return {AnchorBox} | 1517 * @return {AnchorBox} |
| 1564 */ | 1518 */ |
| 1565 _anchorBoxForPosition: function(line, column) | 1519 _anchorBoxForPosition: function(line, column) |
| 1566 { | 1520 { |
| 1567 var metrics = this._textEditor.cursorPositionToCoordinates(line, column)
; | 1521 var metrics = this._textEditor.cursorPositionToCoordinates(line, column)
; |
| 1568 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height)
: null; | 1522 return metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.height)
: null; |
| 1569 }, | 1523 }, |
| 1570 } | 1524 } |
| OLD | NEW |