Add a nonfunctional gutter to editor layout.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-02 15:42:04 -08:00
parent 78161f3341
commit b3c4fd5cce
6 changed files with 116 additions and 111 deletions

View File

@@ -5,7 +5,7 @@ _ = require 'underscore'
module.exports =
class Cursor extends View
@content: ->
@pre class: 'cursor idle', style: 'position: absolute;', => @raw ' '
@pre class: 'cursor idle', => @raw ' '
editor: null
screenPosition: null
@@ -128,15 +128,16 @@ class Cursor extends View
@editor.scrollTop(desiredTop)
autoScrollHorizontally: (position) ->
charsInView = @editor.width() / @width()
charsInView = @editor.lines.width() / @width()
maxScrollMargin = Math.floor((charsInView - 1) / 2)
scrollMargin = Math.min(@editor.hScrollMargin, maxScrollMargin)
margin = scrollMargin * @width()
desiredRight = position.left + @width() + margin
desiredLeft = position.left - margin
cursorLeft = (position.left - @editor.linesPositionLeft())
desiredRight = cursorLeft + @width() + margin
desiredLeft = cursorLeft - margin
if desiredRight > @editor.scrollRight()
@editor.scrollRight(desiredRight)
else if desiredLeft < @editor.scrollLeft()
@editor.scrollLeft(desiredLeft)
if desiredRight > @editor.lines.scrollRight()
@editor.lines.scrollRight(desiredRight)
else if desiredLeft < @editor.lines.scrollLeft()
@editor.lines.scrollLeft(desiredLeft)

View File

@@ -16,7 +16,12 @@ module.exports =
class Editor extends View
@content: ->
@div class: 'editor', tabindex: -1, =>
@div outlet: 'lines'
@div class: 'content', outlet: 'content', =>
@div class: 'gutter', outlet: 'gutter', =>
@div '1'
@div '2'
@div '3'
@div class: 'lines', outlet: 'lines'
@input class: 'hidden-input', outlet: 'hiddenInput'
vScrollMargin: 2
@@ -230,7 +235,10 @@ class Editor extends View
@lineWrapper.clipScreenPosition(screenPosition, options)
pixelPositionForScreenPosition: ({row, column}) ->
{ top: row * @lineHeight, left: column * @charWidth }
{ top: row * @lineHeight, left: @linesPositionLeft() + column * @charWidth }
linesPositionLeft: ->
@lines.position().left + @scrollLeft()
screenPositionFromPixelPosition: ({top, left}) ->
screenPosition = new Point(Math.floor(top / @lineHeight), Math.floor(left / @charWidth))
@@ -261,18 +269,6 @@ class Editor extends View
@lineHeight = fragment.outerHeight()
fragment.remove()
scrollBottom: (newValue) ->
if newValue?
@scrollTop(newValue - @height())
else
@scrollTop() + @height()
scrollRight: (newValue) ->
if newValue?
@scrollLeft(newValue - @width())
else
@scrollLeft() + @width()
getCursor: -> @cursor
getSelection: -> @selection