Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js

Issue 402433007: DevTools: [CodeMirror] remove auto-inserted whitespaces (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline inspector/editor/text-editor-formatter.html Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/inspector/editor/text-editor-formatter-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 var selections = codeMirror.listSelections(); 241 var selections = codeMirror.listSelections();
242 var replacements = []; 242 var replacements = [];
243 for (var i = 0; i < selections.length; ++i) { 243 for (var i = 0; i < selections.length; ++i) {
244 var selection = selections[i]; 244 var selection = selections[i];
245 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? selection.head : selection.anchor; 245 var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? selection.head : selection.anchor;
246 var line = codeMirror.getLine(cur.line); 246 var line = codeMirror.getLine(cur.line);
247 var indent = WebInspector.TextUtils.lineIndent(line); 247 var indent = WebInspector.TextUtils.lineIndent(line);
248 replacements.push("\n" + indent.substring(0, Math.min(cur.ch, indent .length))); 248 replacements.push("\n" + indent.substring(0, Math.min(cur.ch, indent .length)));
249 } 249 }
250 codeMirror.replaceSelections(replacements); 250 codeMirror.replaceSelections(replacements);
251 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces();
251 } 252 }
252 } 253 }
253 254
254 /** 255 /**
255 * @param {!CodeMirror} codeMirror 256 * @param {!CodeMirror} codeMirror
256 */ 257 */
257 CodeMirror.commands.gotoMatchingBracket = function(codeMirror) 258 CodeMirror.commands.gotoMatchingBracket = function(codeMirror)
258 { 259 {
259 var updatedSelections = []; 260 var updatedSelections = [];
260 var selections = codeMirror.listSelections(); 261 var selections = codeMirror.listSelections();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 319
319 codemirror.setSelection(selection.anchor, selection.head, {scroll: false}); 320 codemirror.setSelection(selection.anchor, selection.head, {scroll: false});
320 codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); 321 codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line);
321 } 322 }
322 323
323 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; 324 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000;
324 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; 325 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16;
325 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; 326 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10;
326 327
327 WebInspector.CodeMirrorTextEditor.prototype = { 328 WebInspector.CodeMirrorTextEditor.prototype = {
329 _onAutoAppendedSpaces: function()
330 {
331 this._autoAppendedSpaces = this._autoAppendedSpaces || [];
332 for (var i = 0; i < this._autoAppendedSpaces.length; ++i) {
333 var position = this._autoAppendedSpaces[i].resolve();
334 if (!position)
335 continue;
336 var line = this.line(position.lineNumber);
337 if (line.length === position.columnNumber && WebInspector.TextUtils. lineIndent(line).length === line.length)
338 this._codeMirror.replaceRange("", new CodeMirror.Pos(position.li neNumber, 0), new CodeMirror.Pos(position.lineNumber, position.columnNumber));
339 }
340 this._autoAppendedSpaces = [];
341 var selections = this.selections();
342 for (var i = 0; i < selections.length; ++i) {
343 var selection = selections[i];
344 this._autoAppendedSpaces.push(this.textEditorPositionHandle(selectio n.startLine, selection.startColumn));
345 }
346 },
347
328 /** 348 /**
329 * @param {number} lineNumber 349 * @param {number} lineNumber
330 * @param {number} lineLength 350 * @param {number} lineLength
331 * @param {number} charNumber 351 * @param {number} charNumber
332 * @return {{lineNumber: number, columnNumber: number}} 352 * @return {{lineNumber: number, columnNumber: number}}
333 */ 353 */
334 _normalizePositionForOverlappingColumn: function(lineNumber, lineLength, cha rNumber) 354 _normalizePositionForOverlappingColumn: function(lineNumber, lineLength, cha rNumber)
335 { 355 {
336 var linesCount = this._codeMirror.lineCount(); 356 var linesCount = this._codeMirror.lineCount();
337 var columnNumber = charNumber; 357 var columnNumber = charNumber;
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 isCollapsedBlock = true; 1714 isCollapsedBlock = true;
1695 } else if (line.substr(selection.head.ch - 1, 1) !== "{") { 1715 } else if (line.substr(selection.head.ch - 1, 1) !== "{") {
1696 return CodeMirror.Pass; 1716 return CodeMirror.Pass;
1697 } 1717 }
1698 if (i > 0 && allSelectionsAreCollapsedBlocks !== isCollapsedBlock) 1718 if (i > 0 && allSelectionsAreCollapsedBlocks !== isCollapsedBlock)
1699 return CodeMirror.Pass; 1719 return CodeMirror.Pass;
1700 replacements.push(indentToInsert); 1720 replacements.push(indentToInsert);
1701 allSelectionsAreCollapsedBlocks = isCollapsedBlock; 1721 allSelectionsAreCollapsedBlocks = isCollapsedBlock;
1702 } 1722 }
1703 codeMirror.replaceSelections(replacements); 1723 codeMirror.replaceSelections(replacements);
1704 if (!allSelectionsAreCollapsedBlocks) 1724 if (!allSelectionsAreCollapsedBlocks) {
1725 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces();
1705 return; 1726 return;
1727 }
1706 selections = codeMirror.listSelections(); 1728 selections = codeMirror.listSelections();
1707 var updatedSelections = []; 1729 var updatedSelections = [];
1708 for (var i = 0; i < selections.length; ++i) { 1730 for (var i = 0; i < selections.length; ++i) {
1709 var selection = selections[i]; 1731 var selection = selections[i];
1710 var line = codeMirror.getLine(selection.head.line - 1); 1732 var line = codeMirror.getLine(selection.head.line - 1);
1711 var position = new CodeMirror.Pos(selection.head.line - 1, line.leng th); 1733 var position = new CodeMirror.Pos(selection.head.line - 1, line.leng th);
1712 updatedSelections.push({ 1734 updatedSelections.push({
1713 head: position, 1735 head: position,
1714 anchor: position 1736 anchor: position
1715 }); 1737 });
1716 } 1738 }
1717 codeMirror.setSelections(updatedSelections); 1739 codeMirror.setSelections(updatedSelections);
1740 codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces();
1718 }, 1741 },
1719 1742
1720 /** 1743 /**
1721 * @return {*} 1744 * @return {*}
1722 */ 1745 */
1723 "'}'": function(codeMirror) 1746 "'}'": function(codeMirror)
1724 { 1747 {
1725 if (codeMirror.somethingSelected()) 1748 if (codeMirror.somethingSelected())
1726 return CodeMirror.Pass; 1749 return CodeMirror.Pass;
1727 1750
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; 2405 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : "";
2383 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); 2406 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
2384 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; 2407 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : "";
2385 if (!foregroundColorRule && !backgroundColorRule) 2408 if (!foregroundColorRule && !backgroundColorRule)
2386 return; 2409 return;
2387 2410
2388 var style = document.createElement("style"); 2411 var style = document.createElement("style");
2389 style.textContent = backgroundColorRule + foregroundColorRule; 2412 style.textContent = backgroundColorRule + foregroundColorRule;
2390 document.head.appendChild(style); 2413 document.head.appendChild(style);
2391 })(); 2414 })();
OLDNEW
« no previous file with comments | « LayoutTests/inspector/editor/text-editor-formatter-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698