From 3d36455885a680fc67f40a28eb00616cef12cb69 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 6 Nov 2017 16:29:02 -0800 Subject: [PATCH] Make getNonWordCharacters take a position --- spec/text-editor-spec.js | 15 +++++++-------- src/cursor.js | 2 +- src/text-editor.js | 4 ++-- src/tokenized-buffer.js | 3 ++- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/text-editor-spec.js b/spec/text-editor-spec.js index 382d020d4..72e1e9f53 100644 --- a/spec/text-editor-spec.js +++ b/spec/text-editor-spec.js @@ -2052,14 +2052,13 @@ describe('TextEditor', () => { expect(scopeDescriptors[0].getScopesArray()).toEqual(['source.js']) expect(scopeDescriptors[1].getScopesArray()).toEqual(['source.js', 'string.quoted.single.js']) - editor.setScopedSettingsDelegate({ - getNonWordCharacters (scopes) { - const result = '/\()"\':,.;<>~!@#$%^&*|+=[]{}`?' - if (scopes.some(scope => scope.startsWith('string'))) { - return result - } else { - return result + '-' - } + spyOn(editor.getBuffer().getLanguageMode(), 'getNonWordCharacters').andCallFake(function (position) { + const result = '/\()"\':,.;<>~!@#$%^&*|+=[]{}`?' + const scopes = this.scopeDescriptorForPosition(position).getScopesArray() + if (scopes.some(scope => scope.startsWith('string'))) { + return result + } else { + return result + '-' } }) diff --git a/src/cursor.js b/src/cursor.js index 10bdef804..68303e560 100644 --- a/src/cursor.js +++ b/src/cursor.js @@ -702,7 +702,7 @@ class Cursor extends Model { */ getNonWordCharacters () { - return this.editor.getNonWordCharacters(this.getScopeDescriptor().getScopesArray()) + return this.editor.getNonWordCharacters(this.getBufferPosition()) } changePosition (options, fn) { diff --git a/src/text-editor.js b/src/text-editor.js index a9a51c9b2..b98461b28 100644 --- a/src/text-editor.js +++ b/src/text-editor.js @@ -4106,9 +4106,9 @@ class TextEditor { // for the purpose of word-based cursor movements. // // Returns a {String} containing the non-word characters. - getNonWordCharacters (scopes) { + getNonWordCharacters (position) { const languageMode = this.buffer.getLanguageMode() - return (languageMode.getNonWordCharacters && languageMode.getNonWordCharacters(scopes)) || + return (languageMode.getNonWordCharacters && languageMode.getNonWordCharacters(position)) || this.nonWordCharacters } diff --git a/src/tokenized-buffer.js b/src/tokenized-buffer.js index 614b22970..0ddbebdf1 100644 --- a/src/tokenized-buffer.js +++ b/src/tokenized-buffer.js @@ -59,7 +59,8 @@ class TokenizedBuffer { return this.grammar.name } - getNonWordCharacters (scope) { + getNonWordCharacters (position) { + const scope = this.scopeDescriptorForPosition(position) return this.config.get('editor.nonWordCharacters', {scope}) }