Add ability for placeholder text in mini editor

This commit is contained in:
Ben Ogle
2013-11-25 14:46:54 -08:00
parent 79c6badce8
commit 0c2c739741
3 changed files with 54 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
{View, $, $$} = require './space-pen-extensions'
{View, $, $$$} = require './space-pen-extensions'
TextBuffer = require './text-buffer'
Gutter = require './gutter'
{Point, Range} = require 'telepath'
@@ -86,7 +86,7 @@ class EditorView extends View
if editorOrOptions instanceof Editor
editor = editorOrOptions
else
{editor, editSession, @mini} = editorOrOptions ? {}
{editor, editSession, @mini, placeholderText} = editorOrOptions ? {}
editor ?= editSession # TODO: Remove this line after packages have updated their api to use Editor and EditorView
@id = EditorView.nextEditorId++
@@ -101,6 +101,8 @@ class EditorView extends View
@newCursors = []
@newSelections = []
@setPlaceholderText(placeholderText) if placeholderText
if editor?
@edit(editor)
else if @mini
@@ -587,6 +589,14 @@ class EditorView extends View
@showIndentGuide = showIndentGuide
@resetDisplay()
setPlaceholderText: (placeholderText) ->
return unless @mini
@placeholderText = placeholderText
@requestDisplayUpdate()
getPlaceholderText: ->
@placeholderText
# Checkout the HEAD revision of this editor's file.
checkoutHead: ->
if path = @getPath()
@@ -1210,6 +1220,7 @@ class EditorView extends View
return
@updateRenderedLines()
@updatePlaceholderText()
@highlightCursorLine()
@updateCursorViews()
@updateSelectionViews()
@@ -1269,6 +1280,17 @@ class EditorView extends View
selectionView.highlight()
selectionView.clearAutoscroll()
updatePlaceholderText: ->
return unless @mini
if (not @placeholderText) or @getText()
@find('.placeholder-text').remove()
else if @placeholderText and not @getText()
element = @find('.placeholder-text')
if element.length
element.text(@placeholderText)
else
@underlayer.append($('<span/>', class: 'placeholder-text', text: @placeholderText))
updateRenderedLines: ->
firstVisibleScreenRow = @getFirstVisibleScreenRow()
lastScreenRowToRender = firstVisibleScreenRow + @heightInLines - 1