From e30b2f1c73c586c0f33dc1fe07f454520bf7ce69 Mon Sep 17 00:00:00 2001 From: Russell Lescai Date: Wed, 14 Jan 2015 11:51:21 +1030 Subject: [PATCH 1/6] Allow scoped default File Encoding --- src/project.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/project.coffee b/src/project.coffee index a96788a53..6ca5104e4 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -266,7 +266,6 @@ class Project extends Model # Still needed when deserializing a tokenized buffer buildBufferSync: (absoluteFilePath) -> buffer = new TextBuffer({filePath: absoluteFilePath}) - buffer.setEncoding(atom.config.get('core.fileEncoding')) @addBuffer(buffer) buffer.loadSync() buffer @@ -282,7 +281,6 @@ class Project extends Model throw new Error("Atom can only handle files < 2MB for now.") buffer = new TextBuffer({filePath: absoluteFilePath}) - buffer.setEncoding(atom.config.get('core.fileEncoding')) @addBuffer(buffer) buffer.load() .then((buffer) -> buffer) @@ -311,6 +309,7 @@ class Project extends Model buildEditorForBuffer: (buffer, editorOptions) -> editor = new TextEditor(_.extend({buffer, registerEditor: true}, editorOptions)) + editor.setEncoding(atom.config.get(editor.getRootScopeDescriptor(), "core.fileEncoding")) editor eachBuffer: (args...) -> From b819f681aa49380dba0d5accdea6800d0cf38b25 Mon Sep 17 00:00:00 2001 From: Russell Lescai Date: Wed, 14 Jan 2015 13:05:20 +1030 Subject: [PATCH 2/6] Moved setEncoding to TextEditor constructor. --- src/project.coffee | 1 - src/text-editor.coffee | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/project.coffee b/src/project.coffee index 6ca5104e4..b5477db5f 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -309,7 +309,6 @@ class Project extends Model buildEditorForBuffer: (buffer, editorOptions) -> editor = new TextEditor(_.extend({buffer, registerEditor: true}, editorOptions)) - editor.setEncoding(atom.config.get(editor.getRootScopeDescriptor(), "core.fileEncoding")) editor eachBuffer: (args...) -> diff --git a/src/text-editor.coffee b/src/text-editor.coffee index f69243da1..f3b3bc5c2 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -105,6 +105,8 @@ class TextEditor extends Model @languageMode = new LanguageMode(this) + @setEncoding(atom.config.get(@getRootScopeDescriptor(), "core.fileEncoding")) + @subscribe @$scrollTop, (scrollTop) => @emit 'scroll-top-changed', scrollTop @emitter.emit 'did-change-scroll-top', scrollTop From 3d1baaf3f3fac879c51c81038ae4f5bb8e59c38f Mon Sep 17 00:00:00 2001 From: Russell Lescai Date: Wed, 14 Jan 2015 13:46:21 +1030 Subject: [PATCH 3/6] Added spec. Changed argument order for config get/set. --- spec/text-editor-spec.coffee | 19 +++++++++++++++++++ src/text-editor.coffee | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 432502238..4d4a80d24 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -155,6 +155,25 @@ describe "TextEditor", -> expect(editor2.getSoftTabs()).toBe true expect(editor2.getEncoding()).toBe 'macroman' + it "uses scoped `core.fileEncoding` values" + editor1 = null + editor2 = null + + atom.config.set('core.fileEncoding', 'utf16le') + atom.config.set('core.fileEncoding', 'macroman', { scopeSelector: '.javascript' }) + + waitsForPromise -> + atom.workspace.open('a').then (o) -> editor1 = o + + runs -> + expect(editor1.getEncoding()).toBe 'utf16le' + + waitsForPromise -> + atom.workspace.open('test.js').then (o) -> editor2 = o + + runs -> + expect(editor2.getEncoding()).toBe 'macroman' + describe "title", -> describe ".getTitle()", -> it "uses the basename of the buffer's path as its title, or 'untitled' if the path is undefined", -> diff --git a/src/text-editor.coffee b/src/text-editor.coffee index f3b3bc5c2..8519be042 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -105,7 +105,7 @@ class TextEditor extends Model @languageMode = new LanguageMode(this) - @setEncoding(atom.config.get(@getRootScopeDescriptor(), "core.fileEncoding")) + @setEncoding(atom.config.get("core.fileEncoding", { scope: @getRootScopeDescriptor() })) @subscribe @$scrollTop, (scrollTop) => @emit 'scroll-top-changed', scrollTop From 2f3a9c9e35b6f472cf48cf7f450be86106448fb9 Mon Sep 17 00:00:00 2001 From: Russell Lescai Date: Wed, 14 Jan 2015 14:08:23 +1030 Subject: [PATCH 4/6] Updated js scope selector. --- spec/text-editor-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 4d4a80d24..73bdae101 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -160,7 +160,7 @@ describe "TextEditor", -> editor2 = null atom.config.set('core.fileEncoding', 'utf16le') - atom.config.set('core.fileEncoding', 'macroman', { scopeSelector: '.javascript' }) + atom.config.set('core.fileEncoding', 'macroman', { scopeSelector: '.js' }) waitsForPromise -> atom.workspace.open('a').then (o) -> editor1 = o From 6716e544f0d318abb12fe47caf8bf6a4e80e047a Mon Sep 17 00:00:00 2001 From: Russell Lescai Date: Wed, 14 Jan 2015 15:07:42 +1030 Subject: [PATCH 5/6] Fix spec it function. --- spec/text-editor-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 73bdae101..96819bfa6 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -155,7 +155,7 @@ describe "TextEditor", -> expect(editor2.getSoftTabs()).toBe true expect(editor2.getEncoding()).toBe 'macroman' - it "uses scoped `core.fileEncoding` values" + it "uses scoped `core.fileEncoding` values", -> editor1 = null editor2 = null From c538857cfacf012d5948557724c47ef0fee1a189 Mon Sep 17 00:00:00 2001 From: Russell Lescai Date: Thu, 15 Jan 2015 08:57:25 +1030 Subject: [PATCH 6/6] Removed unnecessary braces. --- spec/text-editor-spec.coffee | 2 +- src/text-editor.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 96819bfa6..5f7c5fabf 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -160,7 +160,7 @@ describe "TextEditor", -> editor2 = null atom.config.set('core.fileEncoding', 'utf16le') - atom.config.set('core.fileEncoding', 'macroman', { scopeSelector: '.js' }) + atom.config.set('core.fileEncoding', 'macroman', scopeSelector: '.js') waitsForPromise -> atom.workspace.open('a').then (o) -> editor1 = o diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 8519be042..b49299afe 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -105,7 +105,7 @@ class TextEditor extends Model @languageMode = new LanguageMode(this) - @setEncoding(atom.config.get("core.fileEncoding", { scope: @getRootScopeDescriptor() })) + @setEncoding(atom.config.get("core.fileEncoding", scope: @getRootScopeDescriptor() )) @subscribe @$scrollTop, (scrollTop) => @emit 'scroll-top-changed', scrollTop