diff --git a/src/app/display-buffer.coffee b/src/app/display-buffer.coffee index 950a8da59..a3cfe3224 100644 --- a/src/app/display-buffer.coffee +++ b/src/app/display-buffer.coffee @@ -19,7 +19,10 @@ class DisplayBuffer foldsById: null markers: null - # Internal: + ### + # Internal # + ### + constructor: (@buffer, options={}) -> @id = @constructor.idCounter++ @languageMode = options.languageMode @@ -32,9 +35,7 @@ class DisplayBuffer @tokenizedBuffer.on 'changed', @handleTokenizedBufferChange @buffer.on 'markers-updated', @handleMarkersUpdated - setVisible: (visible) -> @tokenizedBuffer.setVisible(visible) - # Internal: buildLineMap: -> @lineMap = new LineMap @lineMap.insertAtScreenRow 0, @buildLinesForBufferRows(0, @buffer.getLastRow()) @@ -46,6 +47,12 @@ class DisplayBuffer @trigger 'changed', eventProperties @resumeMarkerObservers() + ### + # Public # + ### + + setVisible: (visible) -> @tokenizedBuffer.setVisible(visible) + # Public: Defines the limit at which the buffer begins to soft wrap text. # # softWrapColumn - A {Number} defining the soft wrap limit. @@ -89,6 +96,7 @@ class DisplayBuffer bufferRowsForScreenRows: (startRow, endRow) -> @lineMap.bufferRowsForScreenRows(startRow, endRow) + # Public: Folds all the foldable lines in the buffer. foldAll: -> for currentRow in [0..@buffer.getLastRow()] [startRow, endRow] = @languageMode.rowRangeForFoldAtBufferRow(currentRow) ? [] @@ -96,6 +104,7 @@ class DisplayBuffer @createFold(startRow, endRow) + # Public: Unfolds all the foldable lines in the buffer. unfoldAll: -> for row in [@buffer.getLastRow()..0] @activeFolds[row]?.forEach (fold) => @destroyFold(fold) @@ -173,24 +182,6 @@ class DisplayBuffer _.find @activeFolds[startRow] ? [], (fold) -> fold.startRow == startRow and fold.endRow == endRow - destroyFold: (fold) -> - @unregisterFold(fold.startRow, fold) - - unless @isFoldContainedByActiveFold(fold) - { startRow, endRow } = fold - bufferRange = new Range([startRow, 0], [endRow, @buffer.lineLengthForRow(endRow)]) - oldScreenRange = @screenLineRangeForBufferRange(bufferRange) - lines = @buildLinesForBufferRows(startRow, endRow) - @lineMap.replaceScreenRows(oldScreenRange.start.row, oldScreenRange.end.row, lines) - newScreenRange = @screenLineRangeForBufferRange(bufferRange) - - start = oldScreenRange.start.row - end = oldScreenRange.end.row - screenDelta = newScreenRange.end.row - oldScreenRange.end.row - bufferDelta = 0 - - @triggerChanged({ start, end, screenDelta, bufferDelta }) - # Public: Removes any folds found that contain the given buffer row. # # bufferRow - The buffer row {Number} to check against @@ -340,6 +331,28 @@ class DisplayBuffer clipScreenPosition: (position, options) -> @lineMap.clipScreenPosition(position, options) + ### + # Internal # + ### + + destroyFold: (fold) -> + @unregisterFold(fold.startRow, fold) + + unless @isFoldContainedByActiveFold(fold) + { startRow, endRow } = fold + bufferRange = new Range([startRow, 0], [endRow, @buffer.lineLengthForRow(endRow)]) + oldScreenRange = @screenLineRangeForBufferRange(bufferRange) + lines = @buildLinesForBufferRows(startRow, endRow) + @lineMap.replaceScreenRows(oldScreenRange.start.row, oldScreenRange.end.row, lines) + newScreenRange = @screenLineRangeForBufferRange(bufferRange) + + start = oldScreenRange.start.row + end = oldScreenRange.end.row + screenDelta = newScreenRange.end.row - oldScreenRange.end.row + bufferDelta = 0 + + @triggerChanged({ start, end, screenDelta, bufferDelta }) + handleBufferChange: (e) -> allFolds = [] # Folds can modify @activeFolds, so first make sure we have a stable array of folds allFolds.push(folds...) for row, folds of @activeFolds @@ -372,6 +385,10 @@ class DisplayBuffer @pendingChangeEvent = null @triggerChanged(event, false) + ### + # Public # + ### + buildLineForBufferRow: (bufferRow) -> @buildLinesForBufferRows(bufferRow, bufferRow) @@ -515,6 +532,10 @@ class DisplayBuffer observeMarker: (id, callback) -> @getMarker(id).observe(callback) + ### + # Internal # + ### + pauseMarkerObservers: -> marker.pauseEvents() for marker in @getMarkers() @@ -525,16 +546,13 @@ class DisplayBuffer for marker in @getMarkers() marker.notifyObservers(bufferChanged: false) - # Internal: destroy: -> @tokenizedBuffer.destroy() @buffer.off 'markers-updated', @handleMarkersUpdated - # Internal: logLines: (start, end) -> @lineMap.logLines(start, end) - # Internal: getDebugSnapshot: -> lines = ["Display Buffer:"] for screenLine, row in @lineMap.linesForScreenRows(0, @getLastRow()) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 704c7070d..ce6b241e7 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -67,30 +67,6 @@ class EditSession getViewClass: -> require 'editor' - # Public: Retrieves the filename of the open file. - # - # This is `'untitled'` if the file is new and not saved to the disk. - # - # Returns a {String}. - getTitle: -> - if path = @getPath() - fsUtils.base(path) - else - 'untitled' - - # Public: Retrieves the filename of the open file, followed by a dash, then the file's directory. - # - # If the file is brand new, the title is `untitled`. - # - # Returns a {String}. - getLongTitle: -> - if path = @getPath() - fileName = fsUtils.base(path) - directory = fsUtils.base(fsUtils.directory(path)) - "#{fileName} - #{directory}" - else - 'untitled' - destroy: -> return if @destroyed @destroyed = true @@ -117,6 +93,34 @@ class EditSession copy: -> EditSession.deserialize(@serialize(), @project) + ### + # Public # + ### + + # Public: Retrieves the filename of the open file. + # + # This is `'untitled'` if the file is new and not saved to the disk. + # + # Returns a {String}. + getTitle: -> + if path = @getPath() + fsUtils.base(path) + else + 'untitled' + + # Public: Retrieves the filename of the open file, followed by a dash, then the file's directory. + # + # If the file is brand new, the title is `untitled`. + # + # Returns a {String}. + getLongTitle: -> + if path = @getPath() + fileName = fsUtils.base(path) + directory = fsUtils.base(fsUtils.directory(path)) + "#{fileName} - #{directory}" + else + 'untitled' + # Public: Compares two `EditSession`s to determine equality. # # Equality is based on the condition that: @@ -309,7 +313,10 @@ class EditSession # # Returns a {Boolean}. isModified: -> @buffer.isModified() - # Internal: + # Public: Identifies if the modified buffer should let you know if it's closing + # without being saved. + # + # Returns a {Boolean}. shouldPromptToSave: -> @isModified() and not @buffer.hasMultipleEditors() # Public: Given a buffer position, this converts it into a screen position. @@ -524,7 +531,10 @@ class EditSession redo: -> @buffer.redo(this) - # Internal: + ### + # Internal # + ### + transact: (fn) -> isNewTransaction = @buffer.transact() oldSelectedRanges = @getSelectedBufferRanges() @@ -536,7 +546,6 @@ class EditSession @commit() if isNewTransaction result - # Internal: commit: -> newSelectedRanges = @getSelectedBufferRanges() @pushOperation @@ -544,10 +553,13 @@ class EditSession editSession?.setSelectedBufferRanges(newSelectedRanges) @buffer.commit() - # Internal: abort: -> @buffer.abort() + ### + # Public # + ### + # Public: Folds all the rows. foldAll: -> @displayBuffer.foldAll() diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 5afa1b918..fbe6694ba 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -26,7 +26,10 @@ class Editor extends View @nextEditorId: 1 - # Internal: Establishes the DOM for the editor. + ### + # Internal # + ### + @content: (params) -> @div class: @classes(params), tabindex: -1, => @subview 'gutter', new Gutter @@ -38,7 +41,6 @@ class Editor extends View @div class: 'vertical-scrollbar', outlet: 'verticalScrollbar', => @div outlet: 'verticalScrollbarContent' - # Internal: Defines the classes available to the editor. @classes: ({mini} = {}) -> classes = ['editor'] classes.push 'mini' if mini @@ -186,6 +188,10 @@ class Editor extends View do (name, method) => @command name, (e) => method.call(this, e); false + ### + # Public # + ### + # Public: Retrieves a single cursor # # Returns a {Cursor}. diff --git a/src/app/image-view.coffee b/src/app/image-view.coffee index 2165ffc6b..2a339576b 100644 --- a/src/app/image-view.coffee +++ b/src/app/image-view.coffee @@ -60,27 +60,12 @@ class ImageView extends ScrollView else @image.hide() - # Internal: - setModel: (imageEditSession) -> - @setPath(imageEditSession?.getPath()) - - # Public: Retrieve's the {Editor}'s pane. # # Returns a {Pane}. getPane: -> @parent('.item-views').parent('.pane').view() - # Internal: - adjustSize: (factor) -> - return unless @loaded and @isVisible() - - newWidth = @image.width() * factor - newHeight = @image.height() * factor - @image.width(newWidth) - @image.height(newHeight) - @centerImage() - # Public: Zooms the image out. # # This is done by a factor of `0.9`. @@ -100,3 +85,19 @@ class ImageView extends ScrollView @image.width(@originalWidth) @image.height(@originalHeight) @centerImage() + + ### + # Internal # + ### + + adjustSize: (factor) -> + return unless @loaded and @isVisible() + + newWidth = @image.width() * factor + newHeight = @image.height() * factor + @image.width(newWidth) + @image.height(newHeight) + @centerImage() + + setModel: (imageEditSession) -> + @setPath(imageEditSession?.getPath()) \ No newline at end of file diff --git a/src/app/pane-axis.coffee b/src/app/pane-axis.coffee index 3d55c744d..f7b8cf7ff 100644 --- a/src/app/pane-axis.coffee +++ b/src/app/pane-axis.coffee @@ -4,7 +4,7 @@ $ = require 'jquery' # Internal: module.exports = class PaneAxis extends View - # Internal: + @deserialize: ({children}) -> childViews = children.map (child) -> deserialize(child) new this(childViews) diff --git a/src/app/pane-container.coffee b/src/app/pane-container.coffee index 06db6890d..48e506877 100644 --- a/src/app/pane-container.coffee +++ b/src/app/pane-container.coffee @@ -6,25 +6,29 @@ module.exports = class PaneContainer extends View registerDeserializer(this) - # Internal: + ### + # Internal # + ### + @deserialize: ({root}) -> container = new PaneContainer container.append(deserialize(root)) if root container.removeEmptyPanes() container - # Internal: The DOM of the pane container. @content: -> @div id: 'panes' - # Internal: initialize: -> @destroyedItemStates = [] - # Internal: serialize: -> deserializer: 'PaneContainer' root: @getRoot()?.serialize() + + ### + # Public # + ### focusNextPane: -> panes = @getPanes() diff --git a/src/app/pane.coffee b/src/app/pane.coffee index 938fcbd67..b042a66fb 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -7,12 +7,14 @@ PaneColumn = require 'pane-column' module.exports = class Pane extends View - # Internal: Defines the pane's DOM. + ### + # Internal # + ### + @content: (wrappedView) -> @div class: 'pane', => @div class: 'item-views', outlet: 'itemViews' - # Internal: @deserialize: ({items, focused, activeItemUri}) -> deserializedItems = _.compact(items.map((item) -> deserialize(item))) pane = new Pane(deserializedItems...) @@ -63,6 +65,10 @@ class Pane extends View @attached = true @trigger 'pane:attached', [this] + ### + # Public # + ### + makeActive: -> for pane in @getContainer().getPanes() when pane isnt this pane.makeInactive() diff --git a/src/app/point.coffee b/src/app/point.coffee index 144081d79..b49a3520c 100644 --- a/src/app/point.coffee +++ b/src/app/point.coffee @@ -160,10 +160,6 @@ class Point isGreaterThanOrEqual: (other) -> @compare(other) >= 0 - # Internal: - inspect: -> - "(#{@row}, #{@column})" - # Public: Converts the {Point} to a String. # # Returns a {String}. @@ -176,6 +172,13 @@ class Point toArray: -> [@row, @column] + ### + # Internal # + ### + + inspect: -> + "(#{@row}, #{@column})" + # Internal: serialize: -> @toArray() diff --git a/src/app/project.coffee b/src/app/project.coffee index a1040389e..f47a8894e 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -17,10 +17,6 @@ module.exports = class Project registerDeserializer(this) - # Internal: - @deserialize: (state) -> - new Project(state.path) - tabLength: 2 softTabs: true softWrap: false @@ -36,15 +32,24 @@ class Project @editSessions = [] @buffers = [] - # Internal: + ### + # Internal # + ### + serialize: -> deserializer: 'Project' path: @getPath() - # Internal: + @deserialize: (state) -> + new Project(state.path) + destroy: -> editSession.destroy() for editSession in @getEditSessions() + ### + # Public # + ### + # Public: Retrieves the project path. # # Returns a {String}. @@ -153,7 +158,16 @@ class Project else @buildEditSessionForBuffer(@bufferForPath(filePath), editSessionOptions) - # Internal: + # Public: Retrieves all the {EditSession}s in the project; that is, the `EditSession`s for all open files. + # + # Returns an {Array} of {EditSession}s. + getEditSessions: -> + new Array(@editSessions...) + + ### + # Internal # + ### + buildEditSessionForBuffer: (buffer, editSessionOptions) -> options = _.extend(@defaultEditSessionOptions(), editSessionOptions) options.project = this @@ -163,23 +177,29 @@ class Project @trigger 'edit-session-created', editSession editSession - # Internal: defaultEditSessionOptions: -> tabLength: @tabLength softTabs: @getSoftTabs() softWrap: @getSoftWrap() - # Public: Retrieves all the {EditSession}s in the project; that is, the `EditSession`s for all open files. - # - # Returns an {Array} of {EditSession}s. - getEditSessions: -> - new Array(@editSessions...) - - # Internal: eachEditSession: (callback) -> callback(editSession) for editSession in @getEditSessions() @on 'edit-session-created', (editSession) -> callback(editSession) + eachBuffer: (args...) -> + subscriber = args.shift() if args.length > 1 + callback = args.shift() + + callback(buffer) for buffer in @getBuffers() + if subscriber + subscriber.subscribe this, 'buffer-created', (buffer) -> callback(buffer) + else + @on 'buffer-created', (buffer) -> callback(buffer) + + ### + # Public # + ### + # Public: Removes an {EditSession} association from the project. # # Returns the removed {EditSession}. @@ -195,17 +215,6 @@ class Project buffers.push editSession.buffer buffers - # Internal: - eachBuffer: (args...) -> - subscriber = args.shift() if args.length > 1 - callback = args.shift() - - callback(buffer) for buffer in @getBuffers() - if subscriber - subscriber.subscribe this, 'buffer-created', (buffer) -> callback(buffer) - else - @on 'buffer-created', (buffer) -> callback(buffer) - # Public: Given a file path, this retrieves or creates a new {Buffer}. # # If the `filePath` already has a `buffer`, that value is used instead. Otherwise, @@ -236,6 +245,9 @@ class Project @trigger 'buffer-created', buffer buffer + # Public: Removes a {Buffer} association from the project. + # + # Returns the removed {Buffer}. removeBuffer: (buffer) -> _.remove(@buffers, buffer) diff --git a/src/app/select-list.coffee b/src/app/select-list.coffee index f0bf754b8..e82c07598 100644 --- a/src/app/select-list.coffee +++ b/src/app/select-list.coffee @@ -6,7 +6,10 @@ fuzzyFilter = require 'fuzzy-filter' module.exports = class SelectList extends View - # Internal: Establishes the DOM for the selection list. + ### + # Internal # + ### + @content: -> @div class: @viewClass(), => @subview 'miniEditor', new Editor(mini: true) @@ -21,7 +24,6 @@ class SelectList extends View inputThrottle: 50 cancelling: false - # Internal: initialize: -> requireStylesheet 'select-list' diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 6797c41de..206b83757 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -13,7 +13,10 @@ class Selection wordwise: false needsAutoscroll: null - # Internal: + ### + # Internal # + ### + constructor: ({@cursor, @marker, @editSession, @goalBufferRange}) -> @cursor.selection = this @editSession.observeMarker @marker, => @screenRangeChanged() @@ -21,7 +24,6 @@ class Selection @cursor = null @destroy() - # Internal: destroy: -> return if @destroyed @destroyed = true @@ -29,13 +31,19 @@ class Selection @trigger 'destroyed' unless @editSession.destroyed @cursor?.destroy() - # Internal: finalize: -> @initialScreenRange = null unless @initialScreenRange?.isEqual(@getScreenRange()) if @isEmpty() @wordwise = false @linewise = false + clearAutoscroll: -> + @needsAutoscroll = null + + ### + # Public # + ### + # Public: Identifies if the selection is highlighting anything. # # Returns a {Boolean}. @@ -54,10 +62,6 @@ class Selection isSingleScreenLine: -> @getScreenRange().isSingleLine() - # Internal: - clearAutoscroll: -> - @needsAutoscroll = null - # Public: Retrieves the screen range for the selection. # # Returns a {Range}. diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 1a5fd2e5e..eee35ccd5 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -29,10 +29,6 @@ class Buffer invalidMarkers: null refcount: 0 - # Internal: - @deserialize: ({path, text}) -> - project.bufferForPath(path, text) - # Public: Creates a new buffer. # # path - A {String} representing the file path @@ -59,7 +55,10 @@ class Buffer @undoManager = new UndoManager(this) - # Internal: + ### + # Internal # + ### + destroy: -> throw new Error("Destroying buffer twice with path '#{@getPath()}'") if @destroyed @file?.off() @@ -75,20 +74,14 @@ class Buffer @destroy() if @refcount <= 0 this - # Internal: serialize: -> deserializer: 'TextBuffer' path: @getPath() text: @getText() if @isModified() - # Public: Identifies if the buffer belongs to multiple editors. - # - # For example, if the {Editor} was split. - # - # Returns a {Boolean}. - hasMultipleEditors: -> @refcount > 1 + @deserialize: ({path, text}) -> + project.bufferForPath(path, text) - # Internal: subscribeToFile: -> @file.on "contents-changed", => if @isModified() @@ -104,6 +97,17 @@ class Buffer @file.on "moved", => @trigger "path-changed", this + + ### + # Public # + ### + + # Public: Identifies if the buffer belongs to multiple editors. + # + # For example, if the {Editor} was split. + # + # Returns a {Boolean}. + hasMultipleEditors: -> @refcount > 1 # Public: Reloads a file in the {EditSession}. # diff --git a/src/app/undo-manager.coffee b/src/app/undo-manager.coffee index d8aaaa70b..624567cf5 100644 --- a/src/app/undo-manager.coffee +++ b/src/app/undo-manager.coffee @@ -2,12 +2,12 @@ _ = require 'underscore' module.exports = +# Internal: The object in charge of managing redo and undo operations. class UndoManager undoHistory: null redoHistory: null currentTransaction: null - # Internal: constructor: -> @clear() diff --git a/src/app/window.coffee b/src/app/window.coffee index a92306629..26881b793 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -9,8 +9,11 @@ require 'space-pen-extensions' deserializers = {} deferredDeserializers = {} +### +# Internal # +### -# Internal: This method is called in any window needing a general environment, including specs +# This method is called in any window needing a general environment, including specs window.setUpEnvironment = -> Config = require 'config' Syntax = require 'syntax' @@ -30,7 +33,7 @@ window.setUpEnvironment = -> if nativeStylesheetPath = fsUtils.resolveOnLoadPath(process.platform, ['css', 'less']) requireStylesheet(nativeStylesheetPath) -# Internal: This method is only called when opening a real application window +# This method is only called when opening a real application window window.startup = -> directory = _.find ['/opt/boxen', '/opt/github', '/usr/local'], (dir) -> fsUtils.isDirectory(dir) if directory