Make the language mode the source of nonWordCharacters

This commit is contained in:
Max Brunsfeld
2017-11-20 09:47:09 -08:00
parent f6c2e0eba4
commit 503d239bc3
2 changed files with 26 additions and 20 deletions

View File

@@ -1,9 +1,7 @@
/** @babel */
import {Emitter, Disposable, CompositeDisposable} from 'event-kit'
import TextEditor from './text-editor'
import ScopeDescriptor from './scope-descriptor'
import Grim from 'grim'
const {Emitter, Disposable, CompositeDisposable} = require('event-kit')
const TextEditor = require('./text-editor')
const ScopeDescriptor = require('./scope-descriptor')
const Grim = require('grim')
const EDITOR_PARAMS_BY_SETTING_KEY = [
['core.fileEncoding', 'encoding'],
@@ -23,7 +21,6 @@ const EDITOR_PARAMS_BY_SETTING_KEY = [
['editor.autoIndentOnPaste', 'autoIndentOnPaste'],
['editor.scrollPastEnd', 'scrollPastEnd'],
['editor.undoGroupingInterval', 'undoGroupingInterval'],
['editor.nonWordCharacters', 'nonWordCharacters'],
['editor.scrollSensitivity', 'scrollSensitivity']
]
@@ -38,7 +35,8 @@ const EDITOR_PARAMS_BY_SETTING_KEY = [
// them for observation via `atom.textEditors.add`. **Important:** When you're
// done using your editor, be sure to call `dispose` on the returned disposable
// to avoid leaking editors.
export default class TextEditorRegistry {
module.exports =
class TextEditorRegistry {
constructor ({config, assert, packageManager}) {
this.assert = assert
this.config = config
@@ -105,7 +103,10 @@ export default class TextEditorRegistry {
let scope = null
if (params.buffer) {
scope = new ScopeDescriptor({scopes: [params.buffer.getLanguageMode().getGrammar().scopeName]})
const {grammar} = params.buffer.getLanguageMode()
if (grammar) {
scope = new ScopeDescriptor({scopes: [grammar.scopeName]})
}
}
Object.assign(params, this.textEditorParamsForScope(scope))

View File

@@ -22,6 +22,8 @@ const NON_WHITESPACE_REGEXP = /\S/
const ZERO_WIDTH_NBSP = '\ufeff'
let nextId = 0
const DEFAULT_NON_WORD_CHARACTERS = "/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-…"
// Essential: This class represents all essential editing state for a single
// {TextBuffer}, including cursor and selection positions, folds, and soft wraps.
// If you're manipulating the state of an editor, use this class.
@@ -141,7 +143,6 @@ class TextEditor {
this.autoIndent = (params.autoIndent != null) ? params.autoIndent : true
this.autoIndentOnPaste = (params.autoIndentOnPaste != null) ? params.autoIndentOnPaste : true
this.undoGroupingInterval = (params.undoGroupingInterval != null) ? params.undoGroupingInterval : 300
this.nonWordCharacters = (params.nonWordCharacters != null) ? params.nonWordCharacters : "/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-…"
this.softWrapped = (params.softWrapped != null) ? params.softWrapped : false
this.softWrapAtPreferredLineLength = (params.softWrapAtPreferredLineLength != null) ? params.softWrapAtPreferredLineLength : false
this.preferredLineLength = (params.preferredLineLength != null) ? params.preferredLineLength : 80
@@ -310,10 +311,6 @@ class TextEditor {
this.undoGroupingInterval = value
break
case 'nonWordCharacters':
this.nonWordCharacters = value
break
case 'scrollSensitivity':
this.scrollSensitivity = value
break
@@ -717,7 +714,7 @@ class TextEditor {
// Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidChangeGrammar (callback) {
return this.buffer.onDidChangeLanguageMode(() => {
callback(this.buffer.getLanguageMode().getGrammar())
callback(this.buffer.getLanguageMode().grammar)
})
}
@@ -3375,8 +3372,9 @@ class TextEditor {
// whitespace.
usesSoftTabs () {
const languageMode = this.buffer.getLanguageMode()
const hasIsRowCommented = languageMode.isRowCommented
for (let bufferRow = 0, end = Math.min(1000, this.buffer.getLastRow()); bufferRow <= end; bufferRow++) {
if (languageMode.isRowCommented(bufferRow)) continue
if (hasIsRowCommented && languageMode.isRowCommented(bufferRow)) continue
const line = this.buffer.lineForRow(bufferRow)
if (line[0] === ' ') return true
if (line[0] === '\t') return false
@@ -3561,7 +3559,12 @@ class TextEditor {
// Experimental: Get a notification when async tokenization is completed.
onDidTokenize (callback) {
return this.buffer.getLanguageMode().onDidTokenize(callback)
const languageMode = this.buffer.getLanguageMode()
if (languageMode.onDidTokenize) {
return this.buffer.getLanguageMode().onDidTokenize(callback)
} else {
return new Disposable(() => {})
}
}
/*
@@ -4106,8 +4109,10 @@ class TextEditor {
// Returns a {String} containing the non-word characters.
getNonWordCharacters (position) {
const languageMode = this.buffer.getLanguageMode()
return (languageMode.getNonWordCharacters && languageMode.getNonWordCharacters(position)) ||
this.nonWordCharacters
return (
languageMode.getNonWordCharacters &&
languageMode.getNonWordCharacters(position || Point(0, 0))
) || DEFAULT_NON_WORD_CHARACTERS
}
/*
@@ -4116,7 +4121,7 @@ class TextEditor {
handleLanguageModeChange () {
this.unfoldAll()
this.emitter.emit('did-change-grammar', this.buffer.getLanguageMode().getGrammar())
this.emitter.emit('did-change-grammar', this.buffer.getLanguageMode().grammar)
}
/*