mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Merge pull request #1161 from atom/bo-editor-placeholder-text
Add ability for placeholder text in mini editor
This commit is contained in:
@@ -1934,7 +1934,6 @@ describe "EditorView", ->
|
||||
miniEditor.setText(" and indented line")
|
||||
expect(miniEditor.renderedLines.find('.indent-guide').length).toBe 0
|
||||
|
||||
|
||||
it "lets you set the grammar", ->
|
||||
miniEditor = new EditorView(mini: true)
|
||||
miniEditor.setText("var something")
|
||||
@@ -1946,6 +1945,31 @@ describe "EditorView", ->
|
||||
# doesn't allow regular editors to set grammars
|
||||
expect(-> editorView.setGrammar()).toThrow()
|
||||
|
||||
describe "placeholderText", ->
|
||||
it "is hidden and shown when appropriate", ->
|
||||
miniEditor = new EditorView(mini: true, placeholderText: 'octokitten')
|
||||
miniEditor.attachToDom()
|
||||
|
||||
expect(miniEditor.underlayer.find('.placeholder-text')).toExist()
|
||||
|
||||
miniEditor.setText("var something")
|
||||
expect(miniEditor.underlayer.find('.placeholder-text')).not.toExist()
|
||||
|
||||
miniEditor.setText("")
|
||||
expect(miniEditor.underlayer.find('.placeholder-text')).toExist()
|
||||
|
||||
it "can be set", ->
|
||||
miniEditor = new EditorView(mini: true)
|
||||
miniEditor.attachToDom()
|
||||
|
||||
expect(miniEditor.find('.placeholder-text').text()).toEqual ''
|
||||
|
||||
miniEditor.setPlaceholderText 'octokitten'
|
||||
expect(miniEditor.find('.placeholder-text').text()).toEqual 'octokitten'
|
||||
|
||||
miniEditor.setPlaceholderText 'new one'
|
||||
expect(miniEditor.find('.placeholder-text').text()).toEqual 'new one'
|
||||
|
||||
describe "when the editor.showLineNumbers config is false", ->
|
||||
it "doesn't render any line numbers", ->
|
||||
expect(editorView.gutter.lineNumbers).toBeVisible()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@import "ui-variables";
|
||||
@import "octicon-utf-codes";
|
||||
@import "octicon-mixins";
|
||||
|
||||
@@ -173,4 +174,8 @@
|
||||
.scroll-view {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.placeholder-text {
|
||||
color: @text-color-subtle;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user