From ecc50506c7ee4d3e97cec688635e87788d8cfcfa Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 27 Jan 2013 12:54:23 -0800 Subject: [PATCH] Render trailing carriage return as an invisible --- spec/app/editor-spec.coffee | 14 ++++++++++++++ src/app/editor.coffee | 5 +++-- src/app/token.coffee | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index f8c6b1cab..f5a86ccbf 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1604,6 +1604,20 @@ describe "Editor", -> expect(rightEditor.find(".line:first").text()).toBe "_tab _;" expect(leftEditor.find(".line:first").text()).toBe "_tab _;" + it "displays trailing carriage return using a visible non-empty value", -> + editor.setText "a line that ends with a carriage return\r\n" + editor.attachToDom() + + expect(config.get("editor.showInvisibles")).toBeFalsy() + expect(editor.renderedLines.find('.line:first').text()).toBe "a line that ends with a carriage return\n" + + config.set("editor.showInvisibles", true) + cr = editor.invisibles?.cr + expect(cr).toBeTruthy() + eol = editor.invisibles?.eol + expect(eol).toBeTruthy() + expect(editor.renderedLines.find('.line:first').text()).toBe "a line that ends with a carriage return#{cr}#{eol}" + describe "gutter rendering", -> beforeEach -> editor.attachToDom(heightInLines: 5.5) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 9acca2936..bd4f93934 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -311,9 +311,10 @@ class Editor extends View setInvisibles: (@invisibles={}) -> _.defaults @invisibles, - eol: '\u00ac', - space: '\u2022', + eol: '\u00ac' + space: '\u2022' tab: '\u00bb' + cr: '\u00a4' @resetDisplay() checkoutHead: -> @getBuffer().checkoutHead() diff --git a/src/app/token.coffee b/src/app/token.coffee index e141dd7bf..0c595c908 100644 --- a/src/app/token.coffee +++ b/src/app/token.coffee @@ -80,5 +80,8 @@ class Token if hasTrailingWhitespace html = html.replace /[ ]+$/, (match) -> "" + if invisibles.cr + html = html.replace /\r$/, (match) -> + "" html