mirror of
https://github.com/atom/atom.git
synced 2026-01-26 15:28:27 -05:00
🎨 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:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user