From 502b463a728d071ce099ccb0a4291309df454565 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 10 May 2012 16:59:46 -0600 Subject: [PATCH] WIP: Adding an artificial scrollbar so we can render content before we scroll. It's blue. --- src/app/editor.coffee | 16 +++++++++++++--- static/editor.css | 13 ++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 0712b27c8..41d853727 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -21,6 +21,8 @@ class Editor extends View @subview 'gutter', new Gutter @div class: 'scroller', outlet: 'scroller', => @div class: 'lines', outlet: 'lines', => + @div class: 'scrollbar', outlet: 'scrollbar', => + @div outlet: 'scrollbarContent' @classes: ({mini}) -> classes = ['editor'] @@ -202,8 +204,14 @@ class Editor extends View @insertText(e.originalEvent.data) false - @scroller.on 'scroll', => + # @scroller.on 'mousewheel', => + # console.log "loving that wheel" + # false + + @scrollbar.on 'scroll', => + console.log "scrolling" @updateLines() + @scroller.scrollTop(@scrollbar.scrollTop()) @gutter.scrollTop(@scroller.scrollTop()) if @scroller.scrollLeft() == 0 @gutter.removeClass('drop-shadow') @@ -245,6 +253,7 @@ class Editor extends View @insertLineElements(0, @buildLineElements(@firstRenderedScreenRow, @lastRenderedScreenRow)) @lines.css('padding-bottom', (@getLastScreenRow() - @lastRenderedScreenRow) * @lineHeight) + @scrollbarContent.height(@lineHeight * @screenLineCount()) updateLines: -> firstVisibleScreenRow = @getFirstVisibleScreenRow() @@ -276,10 +285,10 @@ class Editor extends View @lastRenderedScreenRow = lastVisibleScreenRow getFirstVisibleScreenRow: -> - Math.floor(@scroller.scrollTop() / @lineHeight) + Math.floor(@scrollbar.scrollTop() / @lineHeight) getLastVisibleScreenRow: -> - Math.ceil((@scroller.scrollTop() + @scroller.height()) / @lineHeight) - 1 + Math.ceil((@scrollbar.scrollTop() + @scroller.height()) / @lineHeight) - 1 getScreenLines: -> @renderer.getLines() @@ -364,6 +373,7 @@ class Editor extends View if @attached lineElements = @buildLineElements(newRange.start.row, newRange.end.row) @replaceLineElements(oldRange.start.row, oldRange.end.row, lineElements) + @scrollbarContent.height(@lineHeight * @screenLineCount()) buildLineElements: (startRow, endRow) -> charWidth = @charWidth diff --git a/static/editor.css b/static/editor.css index 9ce42143b..782a86528 100644 --- a/static/editor.css +++ b/static/editor.css @@ -35,8 +35,19 @@ -webkit-box-shadow: -2px 0px 10px 2px #222; } +.editor .scrollbar { + position: absolute; + right: 0; + top: 0; + bottom: 0; + width: 10px; + overflow-y: auto; + background: blue; +} + .editor .scroller { - overflow: auto; + overflow-x: auto; + overflow-y: hidden; width: -webkit-flex(1); height: 100%; }