From 261a8aae2d6c20ac3d0c036618d885fa402dc454 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 9 Jan 2013 15:22:37 -0800 Subject: [PATCH 1/9] Remove @autoIndent from Project and EditSession --- src/app/edit-session.coffee | 3 +-- src/app/editor.coffee | 1 - src/app/project.coffee | 5 ----- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 04aa8d523..2eb241a89 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -33,11 +33,10 @@ class EditSession anchorRanges: null cursors: null selections: null - autoIndent: false # TODO: re-enabled auto-indent after fixing the rest of tokenization softTabs: true softWrap: false - constructor: ({@project, @buffer, tabLength, @autoIndent, softTabs, @softWrap }) -> + constructor: ({@project, @buffer, tabLength, softTabs, @softWrap }) -> @softTabs = @buffer.usesSoftTabs() ? softTabs ? true @languageMode = new LanguageMode(this, @buffer.getExtension()) @displayBuffer = new DisplayBuffer(@buffer, { @languageMode, tabLength }) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 5a67ef28e..651811574 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -80,7 +80,6 @@ class Editor extends View buffer: new Buffer() softWrap: false tabLength: 2 - autoIndent: false softTabs: true @editSessions.push editSession diff --git a/src/app/project.coffee b/src/app/project.coffee index d49a1dae9..82d2f18dd 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -16,7 +16,6 @@ class Project new Project(state.path, state.grammarOverridesByPath) tabLength: 2 - autoIndent: true softTabs: true softWrap: false rootDirectory: null @@ -91,9 +90,6 @@ class Project relativize: (fullPath) -> fullPath.replace(@getPath(), "").replace(/^\//, '') - getAutoIndent: -> @autoIndent - setAutoIndent: (@autoIndent) -> - getSoftTabs: -> @softTabs setSoftTabs: (@softTabs) -> @@ -114,7 +110,6 @@ class Project defaultEditSessionOptions: -> tabLength: @tabLength - autoIndent: @getAutoIndent() softTabs: @getSoftTabs() softWrap: @getSoftWrap() From f5ee676e5e25a62c9128d276a37db097ae21799d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 9 Jan 2013 15:24:04 -0800 Subject: [PATCH 2/9] Pass autoIndent as an option flag Instead of querying EditSession for autoIndenting --- spec/app/edit-session-spec.coffee | 56 +++++++++++-------------------- src/app/edit-session.coffee | 22 ++++++++---- src/app/editor.coffee | 4 +-- src/app/selection.coffee | 8 ++--- 4 files changed, 41 insertions(+), 49 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 4b70927d9..f82d7b263 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -675,10 +675,7 @@ describe "EditSession", -> editSession.insertText('holy cow') expect(editSession.lineForScreenRow(2).fold).toBeUndefined() - describe "when auto-indent is enabled and the `autoIndent` option is true", -> - beforeEach -> - editSession.setAutoIndent(true) - + describe "when auto-indent is enabled", -> describe "when a single newline is inserted", -> describe "when the newline is inserted on a line that starts a new level of indentation", -> it "auto-indents the new line to one additional level of indentation beyond the preceding line", -> @@ -739,16 +736,13 @@ describe "EditSession", -> removeLeadingWhitespace = (text) -> text.replace(/^\s*/, '') describe "when the cursor is preceded only by whitespace", -> - describe "when auto-indent is enabled", -> - beforeEach -> - editSession.setAutoIndent(true) - + describe "when auto-indent is enabled", -> describe "when the cursor's current column is less than the suggested indent level", -> describe "when the indentBasis is inferred from the first line", -> it "indents all lines relative to the suggested indent", -> - editSession.insertText('\n xx') + editSession.insertText('\n xx', autoIndent: true) editSession.setCursorBufferPosition([3, 1]) - editSession.insertText(text, normalizeIndent: true) + editSession.insertText(text, normalizeIndent: true, autoIndent: true) expect(editSession.lineForBufferRow(3)).toBe " while (true) {" expect(editSession.lineForBufferRow(4)).toBe " foo();" @@ -759,7 +753,7 @@ describe "EditSession", -> it "indents all lines relative to the suggested indent", -> editSession.insertText('\n xx') editSession.setCursorBufferPosition([3, 1]) - editSession.insertText(removeLeadingWhitespace(text), normalizeIndent: true, indentBasis: 2) + editSession.insertText(removeLeadingWhitespace(text), normalizeIndent: true, indentBasis: 2, autoIndent: true) expect(editSession.lineForBufferRow(3)).toBe " while (true) {" expect(editSession.lineForBufferRow(4)).toBe " foo();" @@ -775,7 +769,7 @@ describe "EditSession", -> """ editSession.setCursorBufferPosition([1, 0]) - editSession.insertText(text, normalizeIndent: true) + editSession.insertText(text, normalizeIndent: true, autoIndent: true) expect(editSession.lineForBufferRow(1)).toBe "\t\t\twhile (true) {" expect(editSession.lineForBufferRow(2)).toBe "\t\t\t\tfoo();" @@ -791,7 +785,7 @@ describe "EditSession", -> """ editSession.setCursorBufferPosition([1, 0]) - editSession.insertText(text, normalizeIndent: true) + editSession.insertText(text, normalizeIndent: true, autoIndent: true) expect(editSession.lineForBufferRow(1)).toBe "\t\twhile (true) {" expect(editSession.lineForBufferRow(2)).toBe "\t\t\tfoo();" @@ -820,9 +814,6 @@ describe "EditSession", -> expect(editSession.lineForBufferRow(6)).toBe " bar();" describe "if auto-indent is disabled", -> - beforeEach -> - expect(editSession.autoIndent).toBeFalsy() - describe "when the indentBasis is inferred from the first line", -> it "always normalizes indented lines to the cursor's current indentation level", -> editSession.insertText('\n ') @@ -845,7 +836,6 @@ describe "EditSession", -> describe "when the cursor is preceded by non-whitespace characters", -> describe "when the indentBasis is inferred from the first line", -> it "normalizes the indentation level of all lines based on the level of the existing first line", -> - editSession.setAutoIndent(true) editSession.buffer.delete([[2, 0], [2, 2]]) editSession.insertText(text, normalizeIndent:true) @@ -856,7 +846,6 @@ describe "EditSession", -> describe "when an indentBasis is provided", -> it "normalizes the indentation level of all lines based on the level of the existing first line", -> - editSession.setAutoIndent(true) editSession.buffer.delete([[2, 0], [2, 2]]) editSession.insertText(removeLeadingWhitespace(text), normalizeIndent:true, indentBasis: 2) @@ -1311,8 +1300,7 @@ describe "EditSession", -> it "moves the cursor to the end of the leading whitespace and inserts enough whitespace to bring the line to the suggested level of indentaion", -> buffer.insert([5, 0], " \n") editSession.setCursorBufferPosition [5, 0] - editSession.setAutoIndent(true) - editSession.indent() + editSession.indent(autoIndent: true) expect(buffer.lineForRow(5)).toMatch /^\s+$/ expect(buffer.lineForRow(5).length).toBe 6 expect(editSession.getCursorBufferPosition()).toEqual [5, 6] @@ -1323,8 +1311,7 @@ describe "EditSession", -> editSession.softTabs = false buffer.insert([5, 0], "\t\n") editSession.setCursorBufferPosition [5, 0] - editSession.setAutoIndent(true) - editSession.indent() + editSession.indent(autoIndent: true) expect(buffer.lineForRow(5)).toMatch /^\t\t\t$/ expect(editSession.getCursorBufferPosition()).toEqual [5, 3] @@ -1333,8 +1320,7 @@ describe "EditSession", -> it "moves the cursor to the end of the leading whitespace and inserts 'tabLength' spaces into the buffer", -> buffer.insert([7, 0], " \n") editSession.setCursorBufferPosition [7, 2] - editSession.setAutoIndent(true) - editSession.indent() + editSession.indent(autoIndent: true) expect(buffer.lineForRow(7)).toMatch /^\s+$/ expect(buffer.lineForRow(7).length).toBe 8 expect(editSession.getCursorBufferPosition()).toEqual [7, 8] @@ -1345,8 +1331,7 @@ describe "EditSession", -> editSession.softTabs = false buffer.insert([7, 0], "\t\t\t\n") editSession.setCursorBufferPosition [7, 1] - editSession.setAutoIndent(true) - editSession.indent() + editSession.indent(autoIndent: true) expect(buffer.lineForRow(7)).toMatch /^\t\t\t\t$/ expect(editSession.getCursorBufferPosition()).toEqual [7, 4] @@ -1421,17 +1406,16 @@ describe "EditSession", -> expect(editSession.buffer.lineForRow(0)).toBe "var first = function () {" expect(buffer.lineForRow(1)).toBe " var first = function(items) {" - it "preserves the indent level when copying and pasting multiple lines", -> - editSession.setAutoIndent(true) - editSession.setSelectedBufferRange([[4, 4], [7, 5]]) - editSession.copySelectedText() - editSession.setCursorBufferPosition([10, 0]) - editSession.pasteText() + it "preserves the indent level when copying and pasting multiple lines", -> + editSession.setSelectedBufferRange([[4, 4], [7, 5]]) + editSession.copySelectedText() + editSession.setCursorBufferPosition([10, 0]) + editSession.pasteText(autoIndent: true) - expect(editSession.lineForBufferRow(10)).toBe " while(items.length > 0) {" - expect(editSession.lineForBufferRow(11)).toBe " current = items.shift();" - expect(editSession.lineForBufferRow(12)).toBe " current < pivot ? left.push(current) : right.push(current);" - expect(editSession.lineForBufferRow(13)).toBe " }" + expect(editSession.lineForBufferRow(10)).toBe " while(items.length > 0) {" + expect(editSession.lineForBufferRow(11)).toBe " current = items.shift();" + expect(editSession.lineForBufferRow(12)).toBe " current < pivot ? left.push(current) : right.push(current);" + expect(editSession.lineForBufferRow(13)).toBe " }" describe ".indentSelectedRows()", -> describe "when nothing is selected", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 2eb241a89..761c6dba8 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -92,7 +92,6 @@ class EditSession getScrollLeft: -> @scrollLeft setSoftWrapColumn: (@softWrapColumn) -> @displayBuffer.setSoftWrapColumn(@softWrapColumn) - setAutoIndent: (@autoIndent) -> setSoftTabs: (@softTabs) -> getSoftWrap: -> @softWrap @@ -158,18 +157,23 @@ class EditSession getCursorScopes: -> @getCursor().getScopes() logScreenLines: (start, end) -> @displayBuffer.logLines(start, end) - insertText: (text, options) -> + shouldAutoIndent: -> + false + + insertText: (text, options={}) -> + options.autoIndent ?= @shouldAutoIndent() @mutateSelectedText (selection) -> selection.insertText(text, options) insertNewline: -> - @insertText('\n', autoIndent: true) + @insertText('\n') insertNewlineBelow: -> @moveCursorToEndOfLine() @insertNewline() - indent: -> - @mutateSelectedText (selection) -> selection.indent() + indent: (options={})-> + options.autoIndent ?= @shouldAutoIndent() + @mutateSelectedText (selection) -> selection.indent(options) backspace: -> @mutateSelectedText (selection) -> selection.backspace() @@ -216,9 +220,13 @@ class EditSession selection.copy(maintainPasteboard) maintainPasteboard = true - pasteText: -> + pasteText: (options={})-> + options.normalizeIndent ?= true + [text, metadata] = pasteboard.read() - @insertText(text, _.extend(metadata ? {}, normalizeIndent: true)) + _.extend(options, metadata) if metadata + + @insertText(text, options) undo: -> @buffer.undo(this) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 651811574..40b64d64d 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -243,7 +243,7 @@ class Editor extends View insertText: (text, options) -> @activeEditSession.insertText(text, options) insertNewline: -> @activeEditSession.insertNewline() insertNewlineBelow: -> @activeEditSession.insertNewlineBelow() - indent: -> @activeEditSession.indent() + indent: (options) -> @activeEditSession.indent(options) indentSelectedRows: -> @activeEditSession.indentSelectedRows() outdentSelectedRows: -> @activeEditSession.outdentSelectedRows() cutSelection: -> @activeEditSession.cutSelectedText() @@ -380,7 +380,7 @@ class Editor extends View @selectOnMousemoveUntilMouseup() @on "textInput", (e) => - @insertText(e.originalEvent.data, autoIndent: true) + @insertText(e.originalEvent.data) false @scrollView.on 'mousewheel', (e) => diff --git a/src/app/selection.coffee b/src/app/selection.coffee index e7f7c23db..dce6f1b3e 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -179,13 +179,13 @@ class Selection else @cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed - if @editSession.autoIndent and options.autoIndent + if options.autoIndent if text == '\n' @editSession.autoIndentBufferRow(newBufferRange.end.row) else @editSession.autoDecreaseIndentForRow(newBufferRange.start.row) - indent: -> + indent: ({ autoIndent }={})-> { row, column } = @cursor.getBufferPosition() if @isEmpty() @@ -193,7 +193,7 @@ class Selection desiredIndent = @editSession.suggestedIndentForBufferRow(row) delta = desiredIndent - @cursor.getIndentLevel() - if @editSession.autoIndent and delta > 0 + if autoIndent and delta > 0 @insertText(@editSession.buildIndentString(delta)) else @insertText(@editSession.getTabText()) @@ -221,7 +221,7 @@ class Selection if insideExistingLine desiredBasis = @editSession.indentationForBufferRow(currentBufferRow) - else if @editSession.autoIndent + else if options.autoIndent desiredBasis = @editSession.suggestedIndentForBufferRow(currentBufferRow) else desiredBasis = @cursor.getIndentLevel() From 21fa3e5a0f54c93218a94d5befaf7e41581bc563 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 9 Jan 2013 16:26:57 -0800 Subject: [PATCH 3/9] autoIndent is stored as a syntax property --- spec/app/edit-session-spec.coffee | 15 +++++++++++++++ src/app/edit-session.coffee | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index f82d7b263..9dd4375ab 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1915,3 +1915,18 @@ describe "EditSession", -> editSession.setCursorScreenPosition([0, 1]) editSession.buffer.reload() expect(editSession.getCursorScreenPosition()).toEqual [0,1] + + describe "autoIndent", -> + describe "when editor.autoIndent returns true based on the EditSession's grammar scope", -> + it "auto indents lines", -> + syntax.addProperties("." + editSession.languageMode.grammar.scopeName, editor: autoIndent: true ) + editSession.setCursorBufferPosition([1, 30]) + editSession.insertText("\n") + expect(editSession.lineForBufferRow(2)).toBe " " + + describe "when editor.autoIndent returns false based on the EditSession's grammar scope", -> + it "auto indents lines", -> + syntax.addProperties("." + editSession.languageMode.grammar.scopeName, editor: autoIndent: false ) + editSession.setCursorBufferPosition([1, 30]) + editSession.insertText("\n") + expect(editSession.lineForBufferRow(2)).toBe "" diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 761c6dba8..32c751966 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -158,7 +158,7 @@ class EditSession logScreenLines: (start, end) -> @displayBuffer.logLines(start, end) shouldAutoIndent: -> - false + syntax.getProperty(["." + @languageMode.grammar.scopeName], "editor.autoIndent") ? false insertText: (text, options={}) -> options.autoIndent ?= @shouldAutoIndent() From d55dfc8a6fc8ad9f4d732cac8ad0b70a5f5a8e9a Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 10 Jan 2013 09:31:23 -0800 Subject: [PATCH 4/9] AutoIndent is a config property instead of a syntax property --- spec/app/edit-session-spec.coffee | 27 ++++++++++++++++++++------- src/app/edit-session.coffee | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 9dd4375ab..3de078143 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1916,17 +1916,30 @@ describe "EditSession", -> editSession.buffer.reload() expect(editSession.getCursorScreenPosition()).toEqual [0,1] - describe "autoIndent", -> - describe "when editor.autoIndent returns true based on the EditSession's grammar scope", -> - it "auto indents lines", -> - syntax.addProperties("." + editSession.languageMode.grammar.scopeName, editor: autoIndent: true ) + describe "auto-indent", -> + describe "editor.autoIndent", -> + it "auto-indents newlines by default", -> editSession.setCursorBufferPosition([1, 30]) editSession.insertText("\n") expect(editSession.lineForBufferRow(2)).toBe " " - describe "when editor.autoIndent returns false based on the EditSession's grammar scope", -> - it "auto indents lines", -> - syntax.addProperties("." + editSession.languageMode.grammar.scopeName, editor: autoIndent: false ) + it "does not auto-indent newlines if editor.autoIndent is false", -> + config.set("editor.autoIndent", false) editSession.setCursorBufferPosition([1, 30]) editSession.insertText("\n") expect(editSession.lineForBufferRow(2)).toBe "" + + it "auto-indents calls to `indent` by default", -> + editSession.setCursorBufferPosition([1, 30]) + editSession.insertText("\n ") + expect(editSession.lineForBufferRow(2)).toBe " " + editSession.indent() + expect(editSession.lineForBufferRow(2)).toBe " " + + it "does not auto-indents calls to `indent` if editor.autoIndent is false", -> + config.set("editor.autoIndent", false) + editSession.setCursorBufferPosition([1, 30]) + editSession.insertText("\n ") + expect(editSession.lineForBufferRow(2)).toBe " " + editSession.indent() + expect(editSession.lineForBufferRow(2)).toBe " " diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 32c751966..e5d437a23 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -158,7 +158,7 @@ class EditSession logScreenLines: (start, end) -> @displayBuffer.logLines(start, end) shouldAutoIndent: -> - syntax.getProperty(["." + @languageMode.grammar.scopeName], "editor.autoIndent") ? false + config.get("editor.autoIndent") ? true insertText: (text, options={}) -> options.autoIndent ?= @shouldAutoIndent() From 4f0e2c1e9b26cfd034c0c9394c22a2176bb8d7c1 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 10 Jan 2013 09:31:57 -0800 Subject: [PATCH 5/9] Add editor.autoIndentPastedText config option --- spec/app/edit-session-spec.coffee | 24 ++++++++++++++++++++++++ src/app/edit-session.coffee | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 3de078143..67a0ec47c 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1943,3 +1943,27 @@ describe "EditSession", -> expect(editSession.lineForBufferRow(2)).toBe " " editSession.indent() expect(editSession.lineForBufferRow(2)).toBe " " + + describe "editor.autoIndentPastedText", -> + it "does not auto-indent pasted text by default", -> + editSession.setCursorBufferPosition([2, 0]) + editSession.insertText("0\n 2\n 4\n") + editSession.getSelection().setBufferRange([[2,0], [5,0]]) + editSession.cutSelectedText() + + editSession.pasteText() + expect(editSession.lineForBufferRow(2)).toBe "0" + expect(editSession.lineForBufferRow(3)).toBe " 2" + expect(editSession.lineForBufferRow(4)).toBe " 4" + + it "auto-indents pasted text when editor.autoIndentPastedText is true", -> + config.set("editor.autoIndentPastedText", true) + editSession.setCursorBufferPosition([2, 0]) + editSession.insertText("0\n 2\n 4\n") + editSession.getSelection().setBufferRange([[2,0], [5,0]]) + editSession.cutSelectedText() + + editSession.pasteText() + expect(editSession.lineForBufferRow(2)).toBe " 0" + expect(editSession.lineForBufferRow(3)).toBe " 2" + expect(editSession.lineForBufferRow(4)).toBe " 4" diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index e5d437a23..9b08be236 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -160,6 +160,9 @@ class EditSession shouldAutoIndent: -> config.get("editor.autoIndent") ? true + shouldAutoIndentPastedText: -> + config.get("editor.autoIndentPastedText") ? false + insertText: (text, options={}) -> options.autoIndent ?= @shouldAutoIndent() @mutateSelectedText (selection) -> selection.insertText(text, options) @@ -220,12 +223,14 @@ class EditSession selection.copy(maintainPasteboard) maintainPasteboard = true - pasteText: (options={})-> + pasteText: (options={}) -> options.normalizeIndent ?= true + options.autoIndent ?= @shouldAutoIndentPastedText() [text, metadata] = pasteboard.read() _.extend(options, metadata) if metadata + console.log options @insertText(text, options) undo: -> From d2521ca8b81ac5406e67455fe78d3bddc6c8be3d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 10 Jan 2013 09:41:33 -0800 Subject: [PATCH 6/9] Set editor.autoIndent to false for tests Auto-indenting makes it more difficult to write simple tests. So we turn it off. --- spec/app/edit-session-spec.coffee | 6 ++++-- spec/spec-helper.coffee | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 67a0ec47c..36ad90389 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1918,7 +1918,8 @@ describe "EditSession", -> describe "auto-indent", -> describe "editor.autoIndent", -> - it "auto-indents newlines by default", -> + it "auto-indents newlines if editor.autoIndent is undefined (the default)", -> + config.set("editor.autoIndent", undefined) editSession.setCursorBufferPosition([1, 30]) editSession.insertText("\n") expect(editSession.lineForBufferRow(2)).toBe " " @@ -1929,7 +1930,8 @@ describe "EditSession", -> editSession.insertText("\n") expect(editSession.lineForBufferRow(2)).toBe "" - it "auto-indents calls to `indent` by default", -> + it "auto-indents calls to `indent` if editor.autoIndent is undefined (the default)", -> + config.set("editor.autoIndent", undefined) editSession.setCursorBufferPosition([1, 30]) editSession.insertText("\n ") expect(editSession.lineForBufferRow(2)).toBe " " diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index c15eb37b2..6f164e220 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -34,6 +34,7 @@ beforeEach -> spyOn(config, 'load') spyOn(config, 'save') config.set "editor.fontSize", 16 + config.set "editor.autoIndent", false # make editor display updates synchronous spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay() From d53572d54d2232a00b450ebcbe937bda4b26a1ae Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 10 Jan 2013 09:42:20 -0800 Subject: [PATCH 7/9] Rename editor.autoIndentPastedText to editor.autoIndentOnPaste --- spec/app/edit-session-spec.coffee | 6 +++--- src/app/edit-session.coffee | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 36ad90389..2ce626cfb 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1946,7 +1946,7 @@ describe "EditSession", -> editSession.indent() expect(editSession.lineForBufferRow(2)).toBe " " - describe "editor.autoIndentPastedText", -> + describe "editor.autoIndentOnPaste", -> it "does not auto-indent pasted text by default", -> editSession.setCursorBufferPosition([2, 0]) editSession.insertText("0\n 2\n 4\n") @@ -1958,8 +1958,8 @@ describe "EditSession", -> expect(editSession.lineForBufferRow(3)).toBe " 2" expect(editSession.lineForBufferRow(4)).toBe " 4" - it "auto-indents pasted text when editor.autoIndentPastedText is true", -> - config.set("editor.autoIndentPastedText", true) + it "auto-indents pasted text when editor.autoIndentOnPaste is true", -> + config.set("editor.autoIndentOnPaste", true) editSession.setCursorBufferPosition([2, 0]) editSession.insertText("0\n 2\n 4\n") editSession.getSelection().setBufferRange([[2,0], [5,0]]) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 9b08be236..1a20813cc 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -161,7 +161,7 @@ class EditSession config.get("editor.autoIndent") ? true shouldAutoIndentPastedText: -> - config.get("editor.autoIndentPastedText") ? false + config.get("editor.autoIndentOnPaste") ? false insertText: (text, options={}) -> options.autoIndent ?= @shouldAutoIndent() @@ -230,7 +230,6 @@ class EditSession [text, metadata] = pasteboard.read() _.extend(options, metadata) if metadata - console.log options @insertText(text, options) undo: -> From ca41bf070922fe9e9246edffd91a4ee43f2f1239 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 10 Jan 2013 10:28:24 -0800 Subject: [PATCH 8/9] Set auto-indent config defaults --- spec/app/edit-session-spec.coffee | 6 +++--- src/app/edit-session.coffee | 4 ++-- src/app/editor.coffee | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 2ce626cfb..10fbd3d7e 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1918,7 +1918,7 @@ describe "EditSession", -> describe "auto-indent", -> describe "editor.autoIndent", -> - it "auto-indents newlines if editor.autoIndent is undefined (the default)", -> + it "auto-indents newlines if editor.autoIndent is true", -> config.set("editor.autoIndent", undefined) editSession.setCursorBufferPosition([1, 30]) editSession.insertText("\n") @@ -1930,8 +1930,8 @@ describe "EditSession", -> editSession.insertText("\n") expect(editSession.lineForBufferRow(2)).toBe "" - it "auto-indents calls to `indent` if editor.autoIndent is undefined (the default)", -> - config.set("editor.autoIndent", undefined) + it "auto-indents calls to `indent` if editor.autoIndent is true", -> + config.set("editor.autoIndent", true) editSession.setCursorBufferPosition([1, 30]) editSession.insertText("\n ") expect(editSession.lineForBufferRow(2)).toBe " " diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 1a20813cc..8d7d3f03c 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -158,10 +158,10 @@ class EditSession logScreenLines: (start, end) -> @displayBuffer.logLines(start, end) shouldAutoIndent: -> - config.get("editor.autoIndent") ? true + config.get("editor.autoIndent") shouldAutoIndentPastedText: -> - config.get("editor.autoIndentOnPaste") ? false + config.get("editor.autoIndentOnPaste") insertText: (text, options={}) -> options.autoIndent ?= @shouldAutoIndent() diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 40b64d64d..e8bb77dfd 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -17,6 +17,8 @@ class Editor extends View fontSize: 20 showInvisibles: false autosave: false + autoIndent: true + autoIndentOnPaste: false @content: (params) -> @div class: @classes(params), tabindex: -1, => From 0c0d48b8f60120c3fd674f3345d2e6aa8c4552e8 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 10 Jan 2013 10:40:05 -0800 Subject: [PATCH 9/9] Add commands to toggle auto-indent options --- src/app/root-view.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index c62bc7c90..801ecc7f2 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -102,6 +102,10 @@ class RootView extends View config.set("editor.showInvisibles", !config.get("editor.showInvisibles")) @command 'window:toggle-ignored-files', => config.set("core.hideGitIgnoredFiles", not config.core.hideGitIgnoredFiles) + @command 'window:toggle-auto-indent', => + config.set("editor.autoIndent", !config.get("editor.autoIndent")) + @command 'window:toggle-auto-indent-on-paste', => + config.set("editor.autoIndentOnPaste", !config.get("editor.autoIndentOnPaste")) afterAttach: (onDom) -> @focus() if onDom