🎨 Create block decorations in TextEditor

This is just an experiment, although I like that we can hide some information
(irrelevant to the user) behind a clean API.
This commit is contained in:
Antonio Scandurra
2015-11-26 15:40:07 +01:00
parent c8254566ef
commit 89d9a2ce83
2 changed files with 12 additions and 10 deletions

View File

@@ -490,16 +490,11 @@ describe "TextEditorPresenter", ->
presenter = buildPresenter(scrollTop: 0, lineHeight: 10)
expect(presenter.getState().verticalScrollbar.scrollHeight).toBe editor.getScreenLineCount() * 10
addBlockDecorationAtScreenRow = (screenRow) ->
editor.decorateMarker(
editor.markScreenPosition([screenRow, 0], invalidate: "never"),
type: "block",
item: document.createElement("div")
)
blockDecoration1 = addBlockDecorationAtScreenRow(0)
blockDecoration2 = addBlockDecorationAtScreenRow(3)
blockDecoration3 = addBlockDecorationAtScreenRow(7)
# Setting `null` as the DOM element, as it doesn't really matter here.
# Maybe a signal that we should separate models from views?
blockDecoration1 = editor.addBlockDecorationForScreenRow(0, null)
blockDecoration2 = editor.addBlockDecorationForScreenRow(3, null)
blockDecoration3 = editor.addBlockDecorationForScreenRow(7, null)
presenter.setBlockDecorationSize(blockDecoration1, 0, 35.8)
presenter.setBlockDecorationSize(blockDecoration2, 0, 50.3)

View File

@@ -1398,6 +1398,13 @@ class TextEditor extends Model
Section: Decorations
###
addBlockDecorationForScreenRow: (screenRow, element) ->
@decorateMarker(
@markScreenPosition([screenRow, 0], invalidate: "never"),
type: "block",
element: element
)
# Essential: Add a decoration that tracks a {TextEditorMarker}. When the
# marker moves, is invalidated, or is destroyed, the decoration will be
# updated to reflect the marker's state.