mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Properly html escape rendered text in editor and render empty lines.
This commit is contained in:
parent
62d8aa72e2
commit
98947877e5
@ -16,8 +16,14 @@ fdescribe "Editor", ->
|
||||
describe ".setBuffer", ->
|
||||
beforeEach ->
|
||||
|
||||
it "creates a pre element for each line in the buffer", ->
|
||||
it "creates a pre element for each line in the buffer, with the html-escaped text of the line", ->
|
||||
expect(editor.lines.find('pre').length).toEqual(buffer.numLines())
|
||||
expect(buffer.getLine(2)).toContain('<')
|
||||
expect(editor.lines.find('pre:eq(2)').html()).toContain '<'
|
||||
|
||||
it "renders a non-breaking space for empty lines", ->
|
||||
expect(buffer.getLine(10)).toBe ''
|
||||
expect(editor.lines.find('pre:eq(10)').html()).toBe ' '
|
||||
|
||||
it "sets the cursor to the beginning of the file", ->
|
||||
expect(editor.getPosition()).toEqual(row: 0, col: 0)
|
||||
|
1
spec/fixtures/sample.js
vendored
1
spec/fixtures/sample.js
vendored
@ -8,5 +8,6 @@ var quicksort = function () {
|
||||
}
|
||||
return sort(left).concat(pivot).concat(sort(right));
|
||||
};
|
||||
|
||||
return sort(Array.apply(this, arguments));
|
||||
};
|
@ -2,6 +2,7 @@ Template = require 'template'
|
||||
Buffer = require 'buffer'
|
||||
Cursor = require 'cursor'
|
||||
$ = require 'jquery'
|
||||
$$ = require 'template/builder'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
@ -71,8 +72,10 @@ class Editor extends Template
|
||||
setBuffer: (@buffer) ->
|
||||
@lines.empty()
|
||||
for line in @buffer.getLines()
|
||||
line = ' ' if line is ''
|
||||
@lines.append "<pre>#{line}</pre>"
|
||||
if line is ''
|
||||
@lines.append $$.pre -> @raw(' ')
|
||||
else
|
||||
@lines.append $$.pre(line)
|
||||
@setPosition(row: 0, col: 0)
|
||||
|
||||
setPosition: (position) ->
|
||||
|
Loading…
Reference in New Issue
Block a user