mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
ace Editor uses Document held by Buffer.
This commit is contained in:
parent
c2c17f846e
commit
c16c25b69b
@ -23,4 +23,4 @@ describe "App", ->
|
||||
expect(newWindow.editor).toBeDefined()
|
||||
expect(newWindow.editor.buffer).toBeDefined()
|
||||
expect(newWindow.editor.buffer.url).toEqual filePath
|
||||
expect(newWindow.editor.buffer.text).toEqual fs.read(filePath)
|
||||
expect(newWindow.editor.buffer.getText()).toEqual fs.read(filePath)
|
||||
|
@ -6,4 +6,4 @@ describe 'Buffer', ->
|
||||
it "loads the contents of the given url", ->
|
||||
filePath = require.resolve 'fixtures/sample.txt'
|
||||
buffer = new Buffer filePath
|
||||
expect(buffer.text).toBe fs.read(filePath)
|
||||
expect(buffer.getText()).toBe fs.read(filePath)
|
||||
|
@ -17,10 +17,10 @@ describe "Editor", ->
|
||||
describe "constructor", ->
|
||||
it "attaches itself to the #main element and opens a buffer with the given url", ->
|
||||
expect(editor.buffer.url).toEqual filePath
|
||||
expect(mainDiv.children('#editor').html()).not.toBe ''
|
||||
expect(mainDiv.children('.editor').html()).not.toBe ''
|
||||
|
||||
it "populates the editor with the contents of the buffer", ->
|
||||
expect(editor.aceEditor.getSession().getValue()).toBe editor.buffer.text
|
||||
expect(editor.aceEditor.getSession().getValue()).toBe editor.buffer.getText()
|
||||
|
||||
describe 'destroy', ->
|
||||
it 'destroys the ace editor and removes #editor from the dom.', ->
|
||||
@ -28,7 +28,10 @@ describe "Editor", ->
|
||||
|
||||
editor.destroy()
|
||||
expect(editor.aceEditor.destroy).toHaveBeenCalled()
|
||||
expect(mainDiv.children('#editor').length).toBe 0
|
||||
expect(mainDiv.children('.editor').length).toBe 0
|
||||
|
||||
describe "when the text is changed via the ace editor", ->
|
||||
it "updates the buffer text", ->
|
||||
expect(editor.buffer.getText()).not.toMatch /^.ooo/
|
||||
editor.aceEditor.getSession().insert {row: 0, column: 1}, 'ooo'
|
||||
expect(editor.buffer.getText()).toMatch /^.ooo/
|
||||
|
@ -1,9 +1,14 @@
|
||||
fs = require 'fs'
|
||||
{Document} = require 'ace/document'
|
||||
|
||||
module.exports =
|
||||
class Buffer
|
||||
text: null
|
||||
aceDocument: null
|
||||
url: null
|
||||
|
||||
constructor: (@url) ->
|
||||
@text = fs.read @url
|
||||
@aceDocument = new Document fs.read(@url)
|
||||
|
||||
getText: ->
|
||||
@aceDocument.getValue()
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
Buffer = require 'buffer'
|
||||
{EditSession} = require 'ace/edit_session'
|
||||
ace = require 'ace/ace'
|
||||
$ = require 'jquery'
|
||||
|
||||
@ -10,14 +11,17 @@ class Editor
|
||||
constructor: (url) ->
|
||||
@buffer = new Buffer(url)
|
||||
@buildAceEditor()
|
||||
@setText @buffer.text
|
||||
|
||||
setText: (text) ->
|
||||
@aceEditor.getSession().setValue @buffer.text
|
||||
|
||||
buildAceEditor: ->
|
||||
$('#main').append("<div id='editor'>")
|
||||
@aceEditor = ace.edit 'editor'
|
||||
editorElement = $("<div class='editor'>")
|
||||
$('#main').append(editorElement)
|
||||
@aceEditor = ace.edit editorElement[0]
|
||||
@aceEditor.setSession(new EditSession(@buffer.aceDocument))
|
||||
@aceEditor.setTheme(require "ace/theme/twilight")
|
||||
window.x = this
|
||||
|
||||
getAceSession: ->
|
||||
@aceEditor.getSession()
|
||||
|
||||
destroy: ->
|
||||
@aceEditor.destroy()
|
||||
|
Loading…
Reference in New Issue
Block a user