Document ‹ Chocolat API

Document.current()

Class method that returns the current Document.

Returns Document – the active document.

Document.open(path, parent, callback)

Open an existing document or create a new untitled one.

  • path String – the path on disk to open. Pass null to create a new untitled document.
  • parent Object – what to attach the new document to. Currently unused, the only accepted parent is "MainWindow"
  • callback Function(Document) – a function that will be called one the document is initialized, with an instance of Document.

.displayName()

Get the display name of a document.

Returns String – the display name of a document.

.filename()

Get the file name of a document.

Returns String – the filename of a document.

.path()

Get the path of a document.

Returns String – the path of the file on disk, null if it's unsaved.

.rootScope()

Get the root scope of a document, e.g. source.objc or text.html

Returns String – the root scope of the document.

.contextAtLocation(idx)

Get the context (list of scopes) at a particular character index.

  • idx Number – a character index in the string.

Returns Array – a list of scopes for the given index.

.editors()

Get an array of Editor objects for a document.

Returns Array – an array of Editor objects.

.length

Get the length of the document.

Returns Number – the length of the document.

.text

Get or set the text of the document.

Returns String – the content of the document.

.textInRange(rng)

Get the text in a given range

  • rng Range – a range.

Returns String – the text at given range.

.replaceTextInRange(rng, replacement)

Replace the text in rng with replacement.

  • rng Range – a range.
  • replacement String – the replacement string.

.tabSize

Get the document's abstract tab size. If the tab size is set to four, then each hard tab character will show up as the width of four spaces. If using soft tabs, four spaces will act in some way like one tab.

Returns Number – the tab size.

.usesSoftTabs

Get whether the document uses spaces for indentation.

Returns Boolean – whether the document uses soft tabs.

.tabString

Get a string representing the ideal indentation. Remember: text files do not always use a consistent indentation format! (then again, text files aren't limited to the BMP either yet you're using JavaScript).

Returns String – A tab character if hard tabs are enabled. A sequence of spaces if soft tabs are enabled..

.storage()

Access the storage object of the Document (see Storage class).

Returns Storage – the storage.

.performSave()

Save the document. If unsaved, presents a save sheet.

.isUntitled()

Determine whether the document is untitled. Untitled documents don't exist on disk.

Returns Boolean – whether the document is untitled.

.isEdited()

Determine whether the document has unsaved changes.

Returns Boolean – whether the document is edited.