Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 "Ctrl-A": "selectAll", | 76 "Ctrl-A": "selectAll", |
| 77 "Ctrl-Z": "undoAndReveal", | 77 "Ctrl-Z": "undoAndReveal", |
| 78 "Shift-Ctrl-Z": "redoAndReveal", | 78 "Shift-Ctrl-Z": "redoAndReveal", |
| 79 "Ctrl-Y": "redo", | 79 "Ctrl-Y": "redo", |
| 80 "Ctrl-Home": "goDocStart", | 80 "Ctrl-Home": "goDocStart", |
| 81 "Ctrl-Up": "goDocStart", | 81 "Ctrl-Up": "goDocStart", |
| 82 "Ctrl-End": "goDocEnd", | 82 "Ctrl-End": "goDocEnd", |
| 83 "Ctrl-Down": "goDocEnd", | 83 "Ctrl-Down": "goDocEnd", |
| 84 "Ctrl-Left": "goGroupLeft", | 84 "Ctrl-Left": "goGroupLeft", |
| 85 "Ctrl-Right": "goGroupRight", | 85 "Ctrl-Right": "goGroupRight", |
| 86 "Alt-Left": "goLineStart", | 86 "Alt-Left": "moveCamelLeft", |
| 87 "Alt-Right": "goLineEnd", | 87 "Alt-Right": "moveCamelRight", |
| 88 "Shift-Alt-Left": "moveCamelLeftShift", | |
|
vsevik
2014/06/27 11:25:43
consider selectCamelLeft
lushnikov
2014/06/27 11:58:23
Done.
| |
| 89 "Shift-Alt-Right": "moveCamelRightShift", | |
| 88 "Ctrl-Backspace": "delGroupBefore", | 90 "Ctrl-Backspace": "delGroupBefore", |
| 89 "Ctrl-Delete": "delGroupAfter", | 91 "Ctrl-Delete": "delGroupAfter", |
| 90 "Ctrl-/": "toggleComment", | 92 "Ctrl-/": "toggleComment", |
| 91 "Ctrl-D": "selectNextOccurrence", | 93 "Ctrl-D": "selectNextOccurrence", |
| 92 "Ctrl-U": "undoLastSelection", | 94 "Ctrl-U": "undoLastSelection", |
| 93 fallthrough: "devtools-common" | 95 fallthrough: "devtools-common" |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 CodeMirror.keyMap["devtools-mac"] = { | 98 CodeMirror.keyMap["devtools-mac"] = { |
| 97 "Cmd-A" : "selectAll", | 99 "Cmd-A" : "selectAll", |
| 98 "Cmd-Z" : "undoAndReveal", | 100 "Cmd-Z" : "undoAndReveal", |
| 99 "Shift-Cmd-Z": "redoAndReveal", | 101 "Shift-Cmd-Z": "redoAndReveal", |
| 100 "Cmd-Up": "goDocStart", | 102 "Cmd-Up": "goDocStart", |
| 101 "Cmd-Down": "goDocEnd", | 103 "Cmd-Down": "goDocEnd", |
| 102 "Alt-Left": "goGroupLeft", | 104 "Alt-Left": "goGroupLeft", |
| 103 "Alt-Right": "goGroupRight", | 105 "Alt-Right": "goGroupRight", |
| 106 "Ctrl-Left": "moveCamelLeft", | |
| 107 "Ctrl-Right": "moveCamelRight", | |
| 108 "Shift-Ctrl-Left": "moveCamelLeftShift", | |
| 109 "Shift-Ctrl-Right": "moveCamelRightShift", | |
| 104 "Cmd-Left": "goLineStartSmart", | 110 "Cmd-Left": "goLineStartSmart", |
| 105 "Cmd-Right": "goLineEnd", | 111 "Cmd-Right": "goLineEnd", |
| 106 "Alt-Backspace": "delGroupBefore", | 112 "Alt-Backspace": "delGroupBefore", |
| 107 "Alt-Delete": "delGroupAfter", | 113 "Alt-Delete": "delGroupAfter", |
| 108 "Cmd-/": "toggleComment", | 114 "Cmd-/": "toggleComment", |
| 109 "Cmd-D": "selectNextOccurrence", | 115 "Cmd-D": "selectNextOccurrence", |
| 110 "Cmd-U": "undoLastSelection", | 116 "Cmd-U": "undoLastSelection", |
| 111 fallthrough: "devtools-common" | 117 fallthrough: "devtools-common" |
| 112 }; | 118 }; |
| 113 | 119 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 /** | 199 /** |
| 194 * @param {!CodeMirror} codeMirror | 200 * @param {!CodeMirror} codeMirror |
| 195 */ | 201 */ |
| 196 WebInspector.CodeMirrorTextEditor.selectNextOccurrenceCommand = function(codeMir ror) | 202 WebInspector.CodeMirrorTextEditor.selectNextOccurrenceCommand = function(codeMir ror) |
| 197 { | 203 { |
| 198 codeMirror._codeMirrorTextEditor._selectNextOccurrenceController.selectNextO ccurrence(); | 204 codeMirror._codeMirrorTextEditor._selectNextOccurrenceController.selectNextO ccurrence(); |
| 199 } | 205 } |
| 200 CodeMirror.commands.selectNextOccurrence = WebInspector.CodeMirrorTextEditor.sel ectNextOccurrenceCommand; | 206 CodeMirror.commands.selectNextOccurrence = WebInspector.CodeMirrorTextEditor.sel ectNextOccurrenceCommand; |
| 201 | 207 |
| 202 /** | 208 /** |
| 209 * @param {boolean} shift | |
| 210 * @param {!CodeMirror} codeMirror | |
| 211 */ | |
| 212 WebInspector.CodeMirrorTextEditor.moveCamelLeftCommand = function(shift, codeMir ror) | |
| 213 { | |
| 214 codeMirror._codeMirrorTextEditor._doCamelCaseMovement(-1, shift); | |
| 215 } | |
| 216 CodeMirror.commands.moveCamelLeft = WebInspector.CodeMirrorTextEditor.moveCamelL eftCommand.bind(null, false); | |
| 217 CodeMirror.commands.moveCamelLeftShift = WebInspector.CodeMirrorTextEditor.moveC amelLeftCommand.bind(null, true); | |
| 218 | |
| 219 /** | |
| 220 * @param {boolean} shift | |
| 221 * @param {!CodeMirror} codeMirror | |
| 222 */ | |
| 223 WebInspector.CodeMirrorTextEditor.moveCamelRightCommand = function(shift, codeMi rror) | |
| 224 { | |
| 225 codeMirror._codeMirrorTextEditor._doCamelCaseMovement(1, shift); | |
| 226 } | |
| 227 CodeMirror.commands.moveCamelRight = WebInspector.CodeMirrorTextEditor.moveCamel RightCommand.bind(null, false); | |
| 228 CodeMirror.commands.moveCamelRightShift = WebInspector.CodeMirrorTextEditor.move CamelRightCommand.bind(null, true); | |
| 229 | |
| 230 /** | |
| 203 * @param {!CodeMirror} codeMirror | 231 * @param {!CodeMirror} codeMirror |
| 204 */ | 232 */ |
| 205 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) | 233 CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) |
| 206 { | 234 { |
| 207 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); | 235 codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); |
| 208 | 236 |
| 209 function countIndent(line) | 237 function countIndent(line) |
| 210 { | 238 { |
| 211 for (var i = 0; i < line.length; ++i) { | 239 for (var i = 0; i < line.length; ++i) { |
| 212 if (!WebInspector.TextUtils.isSpaceChar(line[i])) | 240 if (!WebInspector.TextUtils.isSpaceChar(line[i])) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 293 |
| 266 codemirror.setSelection(selection.anchor, selection.head, {scroll: false}); | 294 codemirror.setSelection(selection.anchor, selection.head, {scroll: false}); |
| 267 codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); | 295 codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); |
| 268 } | 296 } |
| 269 | 297 |
| 270 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; | 298 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; |
| 271 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; | 299 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| 272 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; | 300 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; |
| 273 | 301 |
| 274 WebInspector.CodeMirrorTextEditor.prototype = { | 302 WebInspector.CodeMirrorTextEditor.prototype = { |
| 303 /** | |
| 304 * @param {number} lineNumber | |
| 305 * @param {number} lineLength | |
| 306 * @param {number} charNumber | |
| 307 * @return {{lineNumber: number, columnNumber: number}} | |
| 308 */ | |
| 309 _normalizePositionForOverlappingColumn: function(lineNumber, lineLength, cha rNumber) | |
| 310 { | |
| 311 var linesCount = this._codeMirror.lineCount(); | |
| 312 var columnNumber = charNumber; | |
| 313 if (charNumber < 0 && lineNumber > 0) { | |
| 314 --lineNumber; | |
| 315 columnNumber = this.line(lineNumber).length; | |
| 316 } else if (charNumber >= lineLength && lineNumber < linesCount - 1) { | |
| 317 ++lineNumber; | |
| 318 columnNumber = 0; | |
| 319 } else { | |
| 320 columnNumber = Number.constrain(charNumber, 0, lineLength); | |
| 321 } | |
| 322 return { | |
| 323 lineNumber: lineNumber, | |
| 324 columnNumber: columnNumber | |
| 325 }; | |
| 326 }, | |
| 327 | |
| 328 /** | |
| 329 * @param {number} lineNumber | |
| 330 * @param {number} columnNumber | |
| 331 * @param {number} direction | |
| 332 * @return {{lineNumber: number, columnNumber: number}} | |
| 333 */ | |
| 334 _camelCaseMoveFromPosition: function(lineNumber, columnNumber, direction) | |
| 335 { | |
| 336 /** | |
| 337 * @param {number} charNumber | |
| 338 * @param {number} length | |
| 339 * @return {boolean} | |
| 340 */ | |
| 341 function valid(charNumber, length) | |
| 342 { | |
| 343 return charNumber >= 0 && charNumber < length; | |
| 344 } | |
| 345 | |
| 346 /** | |
| 347 * @param {string} text | |
| 348 * @param {number} charNumber | |
| 349 * @return {boolean} | |
| 350 */ | |
| 351 function isWordStart(text, charNumber) | |
| 352 { | |
| 353 var position = charNumber; | |
| 354 var nextPosition = charNumber + 1; | |
| 355 return valid(position, text.length) && valid(nextPosition, text.leng th) | |
| 356 && WebInspector.TextUtils.isWordChar(text[position]) && WebInspe ctor.TextUtils.isWordChar(text[nextPosition]) | |
| 357 && WebInspector.TextUtils.isUpperCase(text[position]) && WebInsp ector.TextUtils.isLowerCase(text[nextPosition]); | |
| 358 } | |
| 359 | |
| 360 /** | |
| 361 * @param {string} text | |
| 362 * @param {number} charNumber | |
| 363 * @return {boolean} | |
| 364 */ | |
| 365 function isWordEnd(text, charNumber) | |
| 366 { | |
| 367 var position = charNumber; | |
| 368 var prevPosition = charNumber - 1; | |
| 369 return valid(position, text.length) && valid(prevPosition, text.leng th) | |
| 370 && WebInspector.TextUtils.isWordChar(text[position]) && WebInspe ctor.TextUtils.isWordChar(text[prevPosition]) | |
| 371 && WebInspector.TextUtils.isUpperCase(text[position]) && WebInsp ector.TextUtils.isLowerCase(text[prevPosition]); | |
| 372 } | |
| 373 | |
| 374 /** | |
| 375 * @param {number} lineNumber | |
| 376 * @param {number} lineLength | |
| 377 * @param {number} columnNumber | |
| 378 * @return {{lineNumber: number, columnNumber: number}} | |
| 379 */ | |
| 380 function constrainPosition(lineNumber, lineLength, columnNumber) | |
| 381 { | |
| 382 return { | |
| 383 lineNumber: lineNumber, | |
| 384 columnNumber: Number.constrain(columnNumber, 0, lineLength) | |
| 385 }; | |
| 386 } | |
| 387 | |
| 388 var text = this.line(lineNumber); | |
| 389 var length = text.length; | |
| 390 | |
| 391 if ((columnNumber === length && direction === 1) | |
| 392 || (columnNumber === 0 && direction === -1)) | |
| 393 return this._normalizePositionForOverlappingColumn(lineNumber, lengt h, columnNumber + direction); | |
| 394 | |
| 395 var charNumber = direction === 1 ? columnNumber : columnNumber - 1; | |
| 396 | |
| 397 // Move through initial spaces if any. | |
| 398 while (valid(charNumber, length) && WebInspector.TextUtils.isSpaceChar(t ext[charNumber])) | |
| 399 charNumber += direction; | |
| 400 if (!valid(charNumber, length)) | |
| 401 return constrainPosition(lineNumber, length, charNumber); | |
| 402 | |
| 403 if (WebInspector.TextUtils.isStopChar(text[charNumber])) { | |
| 404 while (valid(charNumber, length) && WebInspector.TextUtils.isStopCha r(text[charNumber])) | |
| 405 charNumber += direction; | |
| 406 if (!valid(charNumber, length)) | |
| 407 return constrainPosition(lineNumber, length, charNumber); | |
| 408 return { | |
| 409 lineNumber: lineNumber, | |
| 410 columnNumber: direction === -1 ? charNumber + 1 : charNumber | |
| 411 }; | |
| 412 } | |
| 413 | |
| 414 charNumber += direction; | |
| 415 while (valid(charNumber, length) && !isWordStart(text, charNumber) && !i sWordEnd(text, charNumber) && WebInspector.TextUtils.isWordChar(text[charNumber] )) | |
| 416 charNumber += direction; | |
| 417 | |
| 418 if (!valid(charNumber, length)) | |
| 419 return constrainPosition(lineNumber, length, charNumber); | |
| 420 if (isWordStart(text, charNumber) || isWordEnd(text, charNumber)) { | |
| 421 return { | |
| 422 lineNumber: lineNumber, | |
| 423 columnNumber: charNumber | |
| 424 }; | |
| 425 } | |
| 426 | |
| 427 return { | |
| 428 lineNumber: lineNumber, | |
| 429 columnNumber: direction === -1 ? charNumber + 1 : charNumber | |
| 430 }; | |
| 431 }, | |
| 432 | |
| 433 /** | |
| 434 * @param {number} direction | |
| 435 * @param {boolean} shift | |
| 436 */ | |
| 437 _doCamelCaseMovement: function(direction, shift) | |
| 438 { | |
| 439 var selections = this.selections(); | |
| 440 for (var i = 0; i < selections.length; ++i) { | |
| 441 var selection = selections[i]; | |
| 442 var move = this._camelCaseMoveFromPosition(selection.endLine, select ion.endColumn, direction); | |
| 443 selection.endLine = move.lineNumber; | |
| 444 selection.endColumn = move.columnNumber; | |
| 445 if (!shift) | |
| 446 selections[i] = selection.collapseToEnd(); | |
| 447 } | |
| 448 this.setSelections(selections); | |
| 449 }, | |
| 450 | |
| 275 dispose: function() | 451 dispose: function() |
| 276 { | 452 { |
| 277 WebInspector.settings.textEditorIndent.removeChangeListener(this._update EditorIndentation, this); | 453 WebInspector.settings.textEditorIndent.removeChangeListener(this._update EditorIndentation, this); |
| 278 WebInspector.settings.showWhitespacesInEditor.removeChangeListener(this. _updateCodeMirrorMode, this); | 454 WebInspector.settings.showWhitespacesInEditor.removeChangeListener(this. _updateCodeMirrorMode, this); |
| 279 WebInspector.settings.textEditorBracketMatching.removeChangeListener(thi s._enableBracketMatchingIfNeeded, this); | 455 WebInspector.settings.textEditorBracketMatching.removeChangeListener(thi s._enableBracketMatchingIfNeeded, this); |
| 280 }, | 456 }, |
| 281 | 457 |
| 282 _enableBracketMatchingIfNeeded: function() | 458 _enableBracketMatchingIfNeeded: function() |
| 283 { | 459 { |
| 284 this._codeMirror.setOption("autoCloseBrackets", WebInspector.settings.te xtEditorBracketMatching.get() ? { explode: false } : false); | 460 this._codeMirror.setOption("autoCloseBrackets", WebInspector.settings.te xtEditorBracketMatching.get() ? { explode: false } : false); |
| (...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2127 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; | 2303 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; |
| 2128 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); | 2304 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); |
| 2129 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; | 2305 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; |
| 2130 if (!foregroundColorRule && !backgroundColorRule) | 2306 if (!foregroundColorRule && !backgroundColorRule) |
| 2131 return; | 2307 return; |
| 2132 | 2308 |
| 2133 var style = document.createElement("style"); | 2309 var style = document.createElement("style"); |
| 2134 style.textContent = backgroundColorRule + foregroundColorRule; | 2310 style.textContent = backgroundColorRule + foregroundColorRule; |
| 2135 document.head.appendChild(style); | 2311 document.head.appendChild(style); |
| 2136 })(); | 2312 })(); |
| OLD | NEW |