mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Fix maintenance of grammars for copied editors
This commit is contained in:
@@ -57,7 +57,7 @@ describe "TextEditor", ->
|
||||
expect(editor.tokensForScreenRow(1).length).toBe 2 # soft tab
|
||||
|
||||
describe ".copy()", ->
|
||||
it "returns a different edit session with the same initial state", ->
|
||||
it "returns a different editor with the same initial state", ->
|
||||
editor.setSelectedBufferRange([[1, 2], [3, 4]])
|
||||
editor.addSelectionForBufferRange([[5, 6], [7, 8]], reversed: true)
|
||||
editor.firstVisibleScreenRow = 5
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
/** @babel */
|
||||
|
||||
import {Disposable} from 'event-kit'
|
||||
|
||||
module.exports = Object.freeze({
|
||||
name: 'Null Grammar',
|
||||
scopeName: 'text.plain'
|
||||
scopeName: 'text.plain',
|
||||
onDidUpdate (callback) {
|
||||
return new Disposable(noop)
|
||||
}
|
||||
})
|
||||
|
||||
function noop () {}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import {Emitter, Disposable, CompositeDisposable} from 'event-kit'
|
||||
import {Point, Range} from 'atom'
|
||||
import NullGrammar from './null-grammar'
|
||||
|
||||
const EDITOR_SETTER_NAMES_BY_SETTING_KEY = [
|
||||
['core.fileEncoding', 'setEncoding'],
|
||||
@@ -129,6 +130,10 @@ export default class TextEditorRegistry {
|
||||
}
|
||||
|
||||
this.editorsWithMaintainedGrammar.add(editor)
|
||||
if (editor.getGrammar() !== NullGrammar) {
|
||||
this.editorGrammarOverrides[editor.id] = editor.getGrammar().scopeName
|
||||
}
|
||||
|
||||
this.selectGrammarForEditor(editor)
|
||||
this.subscriptions.add(editor.onDidChangePath(() => {
|
||||
this.editorGrammarScores.delete(editor)
|
||||
|
||||
@@ -156,7 +156,7 @@ class TextEditor extends Model
|
||||
|
||||
@buffer ?= new TextBuffer
|
||||
@tokenizedBuffer ?= new TokenizedBuffer({
|
||||
@tabLength, @buffer, @largeFileMode, @assert
|
||||
grammar, @tabLength, @buffer, @largeFileMode, @assert
|
||||
})
|
||||
@displayLayer ?= @buffer.addDisplayLayer()
|
||||
@displayLayer.setTextDecorationLayer(@tokenizedBuffer)
|
||||
@@ -187,9 +187,6 @@ class TextEditor extends Model
|
||||
priority: 0
|
||||
visible: lineNumberGutterVisible
|
||||
|
||||
if grammar?
|
||||
@setGrammar(grammar)
|
||||
|
||||
serialize: ->
|
||||
tokenizedBufferState = @tokenizedBuffer.serialize()
|
||||
|
||||
@@ -557,13 +554,12 @@ class TextEditor extends Model
|
||||
displayLayer = @displayLayer.copy()
|
||||
selectionsMarkerLayer = displayLayer.getMarkerLayer(@buffer.getMarkerLayer(@selectionsMarkerLayer.id).copy().id)
|
||||
softTabs = @getSoftTabs()
|
||||
newEditor = new TextEditor({
|
||||
new TextEditor({
|
||||
@buffer, selectionsMarkerLayer, @tabLength, softTabs,
|
||||
suppressCursorCreation: true,
|
||||
@firstVisibleScreenRow, @firstVisibleScreenColumn,
|
||||
@clipboard, @assert, displayLayer
|
||||
@clipboard, @assert, displayLayer, grammar: @getGrammar()
|
||||
})
|
||||
newEditor
|
||||
|
||||
# Controls visibility based on the given {Boolean}.
|
||||
setVisible: (visible) -> @tokenizedBuffer.setVisible(visible)
|
||||
|
||||
@@ -12,7 +12,7 @@ NullGrammar = require './null-grammar'
|
||||
|
||||
module.exports =
|
||||
class TokenizedBuffer extends Model
|
||||
grammar: NullGrammar
|
||||
grammar: null
|
||||
buffer: null
|
||||
tabLength: null
|
||||
tokenizedLines: null
|
||||
@@ -31,7 +31,7 @@ class TokenizedBuffer extends Model
|
||||
new this(state)
|
||||
|
||||
constructor: (params) ->
|
||||
{@buffer, @tabLength, @largeFileMode, @assert} = params
|
||||
{grammar, @buffer, @tabLength, @largeFileMode, @assert} = params
|
||||
|
||||
@emitter = new Emitter
|
||||
@disposables = new CompositeDisposable
|
||||
@@ -40,7 +40,7 @@ class TokenizedBuffer extends Model
|
||||
@disposables.add @buffer.preemptDidChange (e) => @handleBufferChange(e)
|
||||
@rootScopeDescriptor = new ScopeDescriptor(scopes: ['text.plain'])
|
||||
|
||||
@retokenizeLines()
|
||||
@setGrammar(grammar ? NullGrammar)
|
||||
|
||||
destroyed: ->
|
||||
@disposables.dispose()
|
||||
@@ -79,7 +79,7 @@ class TokenizedBuffer extends Model
|
||||
onDidTokenize: (callback) ->
|
||||
@emitter.on 'did-tokenize', callback
|
||||
|
||||
setGrammar: (grammar, score) ->
|
||||
setGrammar: (grammar) ->
|
||||
return unless grammar? and grammar isnt @grammar
|
||||
|
||||
@grammar = grammar
|
||||
|
||||
@@ -165,8 +165,8 @@ class Workspace extends Model
|
||||
subscribeToAddedItems: ->
|
||||
@onDidAddPaneItem ({item, pane, index}) =>
|
||||
if item instanceof TextEditor
|
||||
# @textEditorRegistry.maintainConfig(item)
|
||||
# @textEditorRegistry.maintainGrammar(item)
|
||||
@textEditorRegistry.maintainConfig(item)
|
||||
@textEditorRegistry.maintainGrammar(item)
|
||||
@emitter.emit 'did-add-text-editor', {textEditor: item, pane, index}
|
||||
|
||||
# Updates the application's title and proxy icon based on whichever file is
|
||||
|
||||
Reference in New Issue
Block a user