From 89d9a2ce832f8cee0f35e5a6fd8bc588163127de Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 26 Nov 2015 15:40:07 +0100 Subject: [PATCH] :art: 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. --- spec/text-editor-presenter-spec.coffee | 15 +++++---------- src/text-editor.coffee | 7 +++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 6f1cf3a70..e3dc9feaa 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -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) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index a151c9dba..f88c9149c 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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.