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

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

Issue 351213006: DevTools: [CodeMirror] indent autodetection should fallback to default indent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | « no previous file | 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 "Cmd-Right": "goLineEnd", 105 "Cmd-Right": "goLineEnd",
106 "Alt-Backspace": "delGroupBefore", 106 "Alt-Backspace": "delGroupBefore",
107 "Alt-Delete": "delGroupAfter", 107 "Alt-Delete": "delGroupAfter",
108 "Cmd-/": "toggleComment", 108 "Cmd-/": "toggleComment",
109 "Cmd-D": "selectNextOccurrence", 109 "Cmd-D": "selectNextOccurrence",
110 "Cmd-U": "undoLastSelection", 110 "Cmd-U": "undoLastSelection",
111 fallthrough: "devtools-common" 111 fallthrough: "devtools-common"
112 }; 112 };
113 113
114 WebInspector.settings.textEditorIndent.addChangeListener(this._updateEditorI ndentation, this); 114 WebInspector.settings.textEditorIndent.addChangeListener(this._updateEditorI ndentation, this);
115 WebInspector.settings.textEditorAutoDetectIndent.addChangeListener(this._upd ateEditorIndentation, this);
115 this._updateEditorIndentation(); 116 this._updateEditorIndentation();
116 WebInspector.settings.showWhitespacesInEditor.addChangeListener(this._update CodeMirrorMode, this); 117 WebInspector.settings.showWhitespacesInEditor.addChangeListener(this._update CodeMirrorMode, this);
117 WebInspector.settings.textEditorBracketMatching.addChangeListener(this._enab leBracketMatchingIfNeeded, this); 118 WebInspector.settings.textEditorBracketMatching.addChangeListener(this._enab leBracketMatchingIfNeeded, this);
118 this._enableBracketMatchingIfNeeded(); 119 this._enableBracketMatchingIfNeeded();
119 120
120 this._codeMirror.setOption("keyMap", WebInspector.isMac() ? "devtools-mac" : "devtools-pc"); 121 this._codeMirror.setOption("keyMap", WebInspector.isMac() ? "devtools-mac" : "devtools-pc");
121 this._codeMirror.setOption("flattenSpans", false); 122 this._codeMirror.setOption("flattenSpans", false);
122 123
123 this._codeMirror.setOption("maxHighlightLength", WebInspector.CodeMirrorText Editor.maxHighlightLength); 124 this._codeMirror.setOption("maxHighlightLength", WebInspector.CodeMirrorText Editor.maxHighlightLength);
124 this._codeMirror.setOption("mode", null); 125 this._codeMirror.setOption("mode", null);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 269 }
269 270
270 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; 271 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000;
271 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; 272 WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16;
272 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; 273 WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10;
273 274
274 WebInspector.CodeMirrorTextEditor.prototype = { 275 WebInspector.CodeMirrorTextEditor.prototype = {
275 dispose: function() 276 dispose: function()
276 { 277 {
277 WebInspector.settings.textEditorIndent.removeChangeListener(this._update EditorIndentation, this); 278 WebInspector.settings.textEditorIndent.removeChangeListener(this._update EditorIndentation, this);
279 WebInspector.settings.textEditorAutoDetectIndent.removeChangeListener(th is._updateEditorIndentation, this);
278 WebInspector.settings.showWhitespacesInEditor.removeChangeListener(this. _updateCodeMirrorMode, this); 280 WebInspector.settings.showWhitespacesInEditor.removeChangeListener(this. _updateCodeMirrorMode, this);
279 WebInspector.settings.textEditorBracketMatching.removeChangeListener(thi s._enableBracketMatchingIfNeeded, this); 281 WebInspector.settings.textEditorBracketMatching.removeChangeListener(thi s._enableBracketMatchingIfNeeded, this);
280 }, 282 },
281 283
282 _enableBracketMatchingIfNeeded: function() 284 _enableBracketMatchingIfNeeded: function()
283 { 285 {
284 this._codeMirror.setOption("autoCloseBrackets", WebInspector.settings.te xtEditorBracketMatching.get() ? { explode: false } : false); 286 this._codeMirror.setOption("autoCloseBrackets", WebInspector.settings.te xtEditorBracketMatching.get() ? { explode: false } : false);
285 }, 287 },
286 288
287 wasShown: function() 289 wasShown: function()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 return "\t"; 322 return "\t";
321 var minimumIndent = Infinity; 323 var minimumIndent = Infinity;
322 for (var i in indents) { 324 for (var i in indents) {
323 if (indents[i] < onePercentFilterThreshold) 325 if (indents[i] < onePercentFilterThreshold)
324 continue; 326 continue;
325 var indent = parseInt(i, 10); 327 var indent = parseInt(i, 10);
326 if (minimumIndent > indent) 328 if (minimumIndent > indent)
327 minimumIndent = indent; 329 minimumIndent = indent;
328 } 330 }
329 if (minimumIndent === Infinity) 331 if (minimumIndent === Infinity)
330 return WebInspector.TextUtils.Indent.FourSpaces; 332 return WebInspector.settings.textEditorIndent.get();
331 return new Array(minimumIndent + 1).join(" "); 333 return new Array(minimumIndent + 1).join(" ");
332 }, 334 },
333 335
334 _updateEditorIndentation: function() 336 _updateEditorIndentation: function()
335 { 337 {
336 var extraKeys = {}; 338 var extraKeys = {};
337 var indent = WebInspector.settings.textEditorIndent.get(); 339 var indent = WebInspector.settings.textEditorIndent.get();
338 if (WebInspector.settings.textEditorAutoDetectIndent.get()) 340 if (WebInspector.settings.textEditorAutoDetectIndent.get())
339 indent = this._guessIndentationLevel(); 341 indent = this._guessIndentationLevel();
340 if (indent === WebInspector.TextUtils.Indent.TabCharacter) { 342 if (indent === WebInspector.TextUtils.Indent.TabCharacter) {
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; 2129 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : "";
2128 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); 2130 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
2129 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; 2131 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : "";
2130 if (!foregroundColorRule && !backgroundColorRule) 2132 if (!foregroundColorRule && !backgroundColorRule)
2131 return; 2133 return;
2132 2134
2133 var style = document.createElement("style"); 2135 var style = document.createElement("style");
2134 style.textContent = backgroundColorRule + foregroundColorRule; 2136 style.textContent = backgroundColorRule + foregroundColorRule;
2135 document.head.appendChild(style); 2137 document.head.appendChild(style);
2136 })(); 2138 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698