mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Prefer using new TextEditor
to Workspace.prototype.buildTextEditor
This commit is contained in:
parent
dbd7817823
commit
3d2e18747f
@ -1,9 +1,11 @@
|
||||
TextEditor = require '../src/text-editor'
|
||||
|
||||
describe "Selection", ->
|
||||
[buffer, editor, selection] = []
|
||||
|
||||
beforeEach ->
|
||||
buffer = atom.project.bufferForPathSync('sample.js')
|
||||
editor = atom.workspace.buildTextEditor(buffer: buffer, tabLength: 2)
|
||||
editor = new TextEditor({buffer: buffer, tabLength: 2})
|
||||
selection = editor.getLastSelection()
|
||||
|
||||
afterEach ->
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} from './async-spec-helpers'
|
||||
import Grim from 'grim'
|
||||
import TextEditor from '../src/text-editor'
|
||||
import TextEditorElement from '../src/text-editor-element'
|
||||
import _, {extend, flatten, last, toArray} from 'underscore-plus'
|
||||
|
||||
@ -4419,7 +4420,7 @@ describe('TextEditorComponent', function () {
|
||||
|
||||
describe('when autoHeight is not assigned on the editor', function () {
|
||||
it('implicitly assigns autoHeight to true and emits a deprecation warning if the editor has its height assigned via an inline style', function () {
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor()
|
||||
element = editor.getElement()
|
||||
element.setUpdatedSynchronously(false)
|
||||
element.style.height = '200px'
|
||||
@ -4434,7 +4435,7 @@ describe('TextEditorComponent', function () {
|
||||
})
|
||||
|
||||
it('implicitly assigns autoHeight to true and emits a deprecation warning if the editor has its height assigned via position absolute with an assigned top and bottom', function () {
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor()
|
||||
element = editor.getElement()
|
||||
element.setUpdatedSynchronously(false)
|
||||
parentElement = document.createElement('div')
|
||||
|
@ -1,3 +1,4 @@
|
||||
TextEditor = require '../src/text-editor'
|
||||
TextEditorElement = require '../src/text-editor-element'
|
||||
{Disposable} = require 'event-kit'
|
||||
|
||||
@ -33,7 +34,7 @@ describe "TextEditorElement", ->
|
||||
describe "when the model is assigned", ->
|
||||
it "adds the 'mini' attribute if .isMini() returns true on the model", ->
|
||||
element = new TextEditorElement
|
||||
model = atom.workspace.buildTextEditor(mini: true)
|
||||
model = new TextEditor({mini: true})
|
||||
element.setModel(model)
|
||||
expect(element.hasAttribute('mini')).toBe true
|
||||
|
||||
@ -52,7 +53,7 @@ describe "TextEditorElement", ->
|
||||
|
||||
describe "when the editor is detached from the DOM and then reattached", ->
|
||||
it "does not render duplicate line numbers", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor
|
||||
editor.setText('1\n2\n3')
|
||||
element = atom.views.getView(editor)
|
||||
|
||||
@ -65,7 +66,7 @@ describe "TextEditorElement", ->
|
||||
expect(element.shadowRoot.querySelectorAll('.line-number').length).toBe initialCount
|
||||
|
||||
it "does not render duplicate decorations in custom gutters", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor
|
||||
editor.setText('1\n2\n3')
|
||||
editor.addGutter({name: 'test-gutter'})
|
||||
marker = editor.markBufferRange([[0, 0], [2, 0]])
|
||||
@ -200,7 +201,7 @@ describe "TextEditorElement", ->
|
||||
|
||||
describe "::getMaxScrollTop", ->
|
||||
it "returns the maximum scroll top that can be applied to the element", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor
|
||||
editor.setText('1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16')
|
||||
element = atom.views.getView(editor)
|
||||
element.style.lineHeight = "10px"
|
||||
|
@ -2,6 +2,7 @@ _ = require 'underscore-plus'
|
||||
randomWords = require 'random-words'
|
||||
TextBuffer = require 'text-buffer'
|
||||
{Point, Range} = TextBuffer
|
||||
TextEditor = require '../src/text-editor'
|
||||
TextEditorPresenter = require '../src/text-editor-presenter'
|
||||
FakeLinesYardstick = require './fake-lines-yardstick'
|
||||
LineTopIndex = require 'line-top-index'
|
||||
@ -18,7 +19,7 @@ describe "TextEditorPresenter", ->
|
||||
spyOn(window, "clearInterval").andCallFake window.fakeClearInterval
|
||||
|
||||
buffer = new TextBuffer(filePath: require.resolve('./fixtures/sample.js'))
|
||||
editor = atom.workspace.buildTextEditor({buffer})
|
||||
editor = new TextEditor({buffer})
|
||||
waitsForPromise -> buffer.load()
|
||||
|
||||
afterEach ->
|
||||
@ -474,6 +475,7 @@ describe "TextEditorPresenter", ->
|
||||
waitsForPromise -> atom.packages.activatePackage('language-javascript')
|
||||
|
||||
runs ->
|
||||
editor.setGrammar(atom.grammars.grammarForScopeName('source.js'))
|
||||
maxLineLength = editor.getMaxScreenLineLength()
|
||||
presenter = buildPresenter(contentFrameWidth: 50, baseCharacterWidth: 10)
|
||||
|
||||
@ -758,6 +760,7 @@ describe "TextEditorPresenter", ->
|
||||
waitsForPromise -> atom.packages.activatePackage('language-javascript')
|
||||
|
||||
runs ->
|
||||
editor.setGrammar(atom.grammars.grammarForScopeName('source.js'))
|
||||
editor.setCursorBufferPosition([3, 6])
|
||||
presenter = buildPresenter()
|
||||
expect(getState(presenter).hiddenInput.width).toBe 10
|
||||
@ -917,6 +920,7 @@ describe "TextEditorPresenter", ->
|
||||
waitsForPromise -> atom.packages.activatePackage('language-javascript')
|
||||
|
||||
runs ->
|
||||
editor.setGrammar(atom.grammars.grammarForScopeName('source.js'))
|
||||
maxLineLength = editor.getMaxScreenLineLength()
|
||||
presenter = buildPresenter(contentFrameWidth: 50, baseCharacterWidth: 10)
|
||||
|
||||
@ -1264,6 +1268,8 @@ describe "TextEditorPresenter", ->
|
||||
expectValues lineStateForScreenRow(presenter, 3), {screenRow: 3, tagCodes: editor.screenLineForScreenRow(3).tagCodes}
|
||||
|
||||
it "includes the .endOfLineInvisibles if the editor.showInvisibles config option is true", ->
|
||||
editor.update({showInvisibles: false, invisibles: {eol: 'X'}})
|
||||
|
||||
editor.setText("hello\nworld\r\n")
|
||||
presenter = buildPresenter(explicitHeight: 25, scrollTop: 0, lineHeight: 10)
|
||||
expect(tagsForCodes(presenter, lineStateForScreenRow(presenter, 0).tagCodes).openTags).not.toContain('invisible-character eol')
|
||||
@ -1730,6 +1736,7 @@ describe "TextEditorPresenter", ->
|
||||
atom.packages.activatePackage('language-javascript')
|
||||
|
||||
runs ->
|
||||
editor.setGrammar(atom.grammars.grammarForScopeName('source.js'))
|
||||
editor.setCursorBufferPosition([1, 4])
|
||||
presenter = buildPresenter(explicitHeight: 20)
|
||||
|
||||
@ -2075,6 +2082,7 @@ describe "TextEditorPresenter", ->
|
||||
atom.packages.activatePackage('language-javascript')
|
||||
|
||||
runs ->
|
||||
editor.setGrammar(atom.grammars.grammarForScopeName('source.js'))
|
||||
editor.setSelectedBufferRanges([
|
||||
[[2, 4], [2, 6]],
|
||||
])
|
||||
@ -3666,7 +3674,7 @@ describe "TextEditorPresenter", ->
|
||||
|
||||
performSetup = ->
|
||||
buffer = new TextBuffer
|
||||
editor = atom.workspace.buildTextEditor({buffer})
|
||||
editor = new TextEditor({buffer})
|
||||
editor.setEditorWidthInChars(80)
|
||||
presenterParams =
|
||||
model: editor
|
||||
|
@ -5524,7 +5524,7 @@ describe "TextEditor", ->
|
||||
|
||||
describe "auto height", ->
|
||||
it "returns true by default but can be customized", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor
|
||||
expect(editor.getAutoHeight()).toBe(true)
|
||||
editor.update({autoHeight: false})
|
||||
expect(editor.getAutoHeight()).toBe(false)
|
||||
@ -5542,10 +5542,10 @@ describe "TextEditor", ->
|
||||
|
||||
describe '.get/setPlaceholderText()', ->
|
||||
it 'can be created with placeholderText', ->
|
||||
newEditor = atom.workspace.buildTextEditor(
|
||||
newEditor = new TextEditor({
|
||||
mini: true
|
||||
placeholderText: 'yep'
|
||||
)
|
||||
})
|
||||
expect(newEditor.getPlaceholderText()).toBe 'yep'
|
||||
|
||||
it 'models placeholderText and emits an event when changed', ->
|
||||
|
@ -1,5 +1,6 @@
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
TextEditor = require '../src/text-editor'
|
||||
Workspace = require '../src/workspace'
|
||||
Project = require '../src/project'
|
||||
platform = require './spec-helper-platform'
|
||||
@ -795,7 +796,7 @@ describe "Workspace", ->
|
||||
|
||||
describe "::isTextEditor(obj)", ->
|
||||
it "returns true when the passed object is an instance of `TextEditor`", ->
|
||||
expect(workspace.isTextEditor(atom.workspace.buildTextEditor())).toBe(true)
|
||||
expect(workspace.isTextEditor(new TextEditor)).toBe(true)
|
||||
expect(workspace.isTextEditor({getText: -> null})).toBe(false)
|
||||
expect(workspace.isTextEditor(null)).toBe(false)
|
||||
expect(workspace.isTextEditor(undefined)).toBe(false)
|
||||
@ -1727,7 +1728,7 @@ describe "Workspace", ->
|
||||
|
||||
describe "when there's no repository for the editor's file", ->
|
||||
it "doesn't do anything", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor = new TextEditor
|
||||
editor.setText("stuff")
|
||||
atom.workspace.checkoutHeadRevision(editor)
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
_ = require 'underscore-plus'
|
||||
{OnigRegExp} = require 'oniguruma'
|
||||
ScopeDescriptor = require './scope-descriptor'
|
||||
NullGrammar = require './null-grammar'
|
||||
|
||||
module.exports =
|
||||
class LanguageMode
|
||||
@ -245,6 +246,9 @@ class LanguageMode
|
||||
@suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options)
|
||||
|
||||
suggestedIndentForLineAtBufferRow: (bufferRow, line, options) ->
|
||||
if @editor.largeFileMode or @editor.tokenizedBuffer.grammar is NullGrammar
|
||||
tokenizedLine = @editor.tokenizedBuffer.buildPlaceholderTokenizedLineForRowWithText(bufferRow, line)
|
||||
else
|
||||
tokenizedLine = @editor.tokenizedBuffer.buildTokenizedLineForRowWithText(bufferRow, line)
|
||||
@suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options)
|
||||
|
||||
|
@ -263,11 +263,13 @@ class TokenizedBuffer extends Model
|
||||
@buildPlaceholderTokenizedLineForRow(row) for row in [startRow..endRow] by 1
|
||||
|
||||
buildPlaceholderTokenizedLineForRow: (row) ->
|
||||
@buildPlaceholderTokenizedLineForRowWithText(row, @buffer.lineForRow(row))
|
||||
|
||||
buildPlaceholderTokenizedLineForRowWithText: (row, text) ->
|
||||
if @grammar isnt NullGrammar
|
||||
openScopes = [@grammar.startIdForScope(@grammar.scopeName)]
|
||||
else
|
||||
openScopes = []
|
||||
text = @buffer.lineForRow(row)
|
||||
tags = [text.length]
|
||||
lineEnding = @buffer.lineEndingForRow(row)
|
||||
new TokenizedLine({openScopes, text, tags, lineEnding, @tokenIterator})
|
||||
|
Loading…
Reference in New Issue
Block a user