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

Unified Diff: Source/devtools/front_end/CodeMirrorTextEditor.js

Issue 19540026: DevTools: [CodeMirror] respect CRLF line endings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/inspector/editor/text-editor-line-breaks.html ('k') | Source/devtools/front_end/SourceFrame.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/CodeMirrorTextEditor.js
diff --git a/Source/devtools/front_end/CodeMirrorTextEditor.js b/Source/devtools/front_end/CodeMirrorTextEditor.js
index 52909f9b28616ae43bc3b0103806624b9c5a1d1e..6f2732aca4b55156af49bed51b30401b4df02ffb 100644
--- a/Source/devtools/front_end/CodeMirrorTextEditor.js
+++ b/Source/devtools/front_end/CodeMirrorTextEditor.js
@@ -135,6 +135,8 @@ WebInspector.CodeMirrorTextEditor = function(url, delegate)
this._codeMirror.setOption("maxHighlightLength", 1000);
this._codeMirror.setOption("mode", null);
+ this._lineSeparator = "\n";
+
this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighlighter(this._codeMirror);
this._blockIndentController = new WebInspector.CodeMirrorTextEditor.BlockIndentController(this._codeMirror);
this._fixWordMovement = new WebInspector.CodeMirrorTextEditor.FixWordMovement(this._codeMirror);
@@ -1028,12 +1030,23 @@ WebInspector.CodeMirrorTextEditor.prototype = {
/**
* @param {string} text
*/
+ _detectLineSeparator: function(text)
+ {
+ this._lineSeparator = text.indexOf("\r\n") >= 0 ? "\r\n" : "\n";
+ },
+
+ /**
+ * @param {string} text
+ */
setText: function(text)
{
this._muteTextChangedEvent = true;
+ var shouldClearHistory = !this._codeMirror.getValue().length;
this._codeMirror.setValue(text);
this._updateEditorIndentation();
- this._codeMirror.clearHistory();
+ if (shouldClearHistory)
+ this._codeMirror.clearHistory();
+ this._detectLineSeparator(text);
delete this._muteTextChangedEvent;
},
@@ -1042,7 +1055,7 @@ WebInspector.CodeMirrorTextEditor.prototype = {
*/
text: function()
{
- return this._codeMirror.getValue();
+ return this._codeMirror.getValue().replace(/\n/g, this._lineSeparator);
},
/**
« no previous file with comments | « LayoutTests/inspector/editor/text-editor-line-breaks.html ('k') | Source/devtools/front_end/SourceFrame.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698