From aff3d308ad49dbe4845b105576c9d9ef1907c05e Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 5 Mar 2012 15:05:49 -0800 Subject: [PATCH 01/14] Store mode object in Buffer --- src/atom/buffer.coffee | 8 ++++++-- src/atom/highlighter.coffee | 9 ++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/atom/buffer.coffee b/src/atom/buffer.coffee index ecf6ecfa3..ea9d961c4 100644 --- a/src/atom/buffer.coffee +++ b/src/atom/buffer.coffee @@ -91,9 +91,10 @@ class Buffer if not @path then throw new Error("Tried to save buffer with no url") fs.write @path, @getText() - modeName: -> + getMode: -> + return @mode if @mode extension = if @path then @path.split('/').pop().split('.').pop() else null - switch extension + modeName = switch extension when 'js' then 'javascript' when 'coffee' then 'coffee' when 'rb', 'ru' then 'ruby' @@ -102,4 +103,7 @@ class Buffer when 'css' then 'css' else 'text' + @mode = new (require("ace/mode/#{modeName}").Mode) + + _.extend(Buffer.prototype, EventEmitter) diff --git a/src/atom/highlighter.coffee b/src/atom/highlighter.coffee index 494d3391f..e1f466a67 100644 --- a/src/atom/highlighter.coffee +++ b/src/atom/highlighter.coffee @@ -5,18 +5,12 @@ EventEmitter = require 'event-emitter' module.exports = class Highlighter buffer: null - tokenizer: null screenLines: [] constructor: (@buffer) -> - @buildTokenizer() @screenLines = @buildLinesForScreenRows('start', 0, @buffer.lastRow()) @buffer.on 'change', (e) => @handleBufferChange(e) - buildTokenizer: -> - Mode = require("ace/mode/#{@buffer.modeName()}").Mode - @tokenizer = (new Mode).getTokenizer() - handleBufferChange: (e) -> oldRange = e.oldRange.copy() newRange = e.newRange.copy() @@ -56,8 +50,9 @@ class Highlighter screenLine buildLineForScreenRow: (state, row) -> + tokenizer = @buffer.getMode().getTokenizer() line = @buffer.getLine(row) - {tokens, state} = @tokenizer.getLineTokens(line, state) + {tokens, state} = tokenizer.getLineTokens(line, state) new ScreenLineFragment(tokens, line, [1, 0], [1, 0], { state }) lineForScreenRow: (row) -> From 3ff8a1e92c867038e2fd0c1ebb6c77e77d620edf Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 5 Mar 2012 15:12:00 -0800 Subject: [PATCH 02/14] Remove insertNewline method --- src/atom/editor.coffee | 3 +-- src/atom/selection.coffee | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 06a204411..6782037c7 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -69,7 +69,7 @@ class Editor extends View @on 'select-left', => @selectLeft() @on 'select-up', => @selectUp() @on 'select-down', => @selectDown() - @on 'newline', => @insertNewline() + @on 'newline', => @insertText("\n") @on 'backspace', => @backspace() @on 'delete', => @delete() @on 'cut', => @cutSelection() @@ -301,7 +301,6 @@ class Editor extends View @selection.selectToBufferPosition(position) insertText: (text) -> @selection.insertText(text) - insertNewline: -> @selection.insertNewline() cutSelection: -> @selection.cut() copySelection: -> @selection.copy() diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index c937d8f88..13e7ee74c 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -83,9 +83,6 @@ class Selection extends View insertText: (text) -> @editor.buffer.change(@getBufferRange(), text) - insertNewline: -> - @insertText('\n') - delete: -> range = @getBufferRange() @editor.buffer.change(range, '') unless range.isEmpty() From 53fc625534fcaed4093fc836e982bf203a01f2a5 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 5 Mar 2012 15:51:56 -0800 Subject: [PATCH 03/14] Inserting a newline indents the cursor (based on information from previous line) --- spec/atom/editor-spec.coffee | 10 ++++++++-- src/atom/editor.coffee | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index c374f848e..0f377433d 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -440,6 +440,14 @@ describe "Editor", -> editor.lines.trigger 'mouseup' expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;" + describe "auto indent/outdent", -> + describe "when newline is inserted", -> + it "indents cursor based on the indentation of previous line", -> + editor.setCursorBufferPosition([4, 29]) + editor.insertText("\n") + + expect(editor.buffer.getLine(5)).toEqual(" ") + describe "selection", -> selection = null @@ -829,5 +837,3 @@ describe "Editor", -> expect(editor.lines.find('.line:eq(5)').text()).toBe ' current = items.shift();' expect(editor.getCursorBufferPosition()).toEqual [4, 29] - - diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 6782037c7..8aaad5663 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -300,7 +300,14 @@ class Editor extends View selectToBufferPosition: (position) -> @selection.selectToBufferPosition(position) - insertText: (text) -> @selection.insertText(text) + insertText: (text) -> + if text[0] == "\n" + tab = " " + state = @lineWrapper.lineForScreenRow(@getRow).state + indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), tab) + text = text[0] + indent + text[1..] + + @selection.insertText(text) cutSelection: -> @selection.cut() copySelection: -> @selection.copy() From 79edb3fcdfb7b5afc66f244f63b0fb48e55f0be2 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 11:08:20 -0800 Subject: [PATCH 04/14] Store tabText in atom. This is a combination of tabsOrSpaces and tabSize. I imagine things like these will be stored in a settings object on `atom` at some point. --- src/atom/app.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/atom/app.coffee b/src/atom/app.coffee index ce79e4a83..fa8f8e239 100644 --- a/src/atom/app.coffee +++ b/src/atom/app.coffee @@ -6,14 +6,16 @@ module.exports = class App keymap: null windows: null + tabText: null constructor: (@loadPath, nativeMethods)-> @windows = [] @setupKeymap() + @tabText = " " setupKeymap: -> @keymap = new GlobalKeymap() - + $(document).on 'keydown', (e) => @keymap.handleKeyEvent(e) open: (url) -> From 668022fb3b06c4fcd3acf9ad7bc8eb4bff49ac6c Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 11:08:46 -0800 Subject: [PATCH 05/14] Outdent works with Ace's Mode classes --- spec/atom/editor-spec.coffee | 12 +++++++++++- src/atom/buffer.coffee | 9 +++++++++ src/atom/editor.coffee | 19 ++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 0f377433d..1905ceb74 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -441,13 +441,23 @@ describe "Editor", -> expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;" describe "auto indent/outdent", -> + beforeEach -> + editor.autoIndent = true + describe "when newline is inserted", -> it "indents cursor based on the indentation of previous line", -> editor.setCursorBufferPosition([4, 29]) editor.insertText("\n") - expect(editor.buffer.getLine(5)).toEqual(" ") + describe "when text that closes a scope entered", -> + it "outdents the text", -> + editor.setCursorBufferPosition([1, 30]) + editor.insertText("\n") + expect(editor.buffer.getLine(2)).toEqual(" ") + editor.insertText("}") + expect(editor.buffer.getLine(2)).toEqual(" }") + describe "selection", -> selection = null diff --git a/src/atom/buffer.coffee b/src/atom/buffer.coffee index ea9d961c4..1e94010cc 100644 --- a/src/atom/buffer.coffee +++ b/src/atom/buffer.coffee @@ -105,5 +105,14 @@ class Buffer @mode = new (require("ace/mode/#{modeName}").Mode) + # API to match Ace's Document class + findMatchingBracket: ({row, column}) -> + {row: 0, column: 0} + + replace:(range, text) -> + # Only used to outdent lines + start = range.start + end = {row: range.start.row, column: range.start.column + atom.tabText.length} + @change(new Range(start, end), "") _.extend(Buffer.prototype, EventEmitter) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 8aaad5663..e9f3895c5 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -31,6 +31,8 @@ class Editor extends View highlighter: null lineWrapper: null undoManager: null + autoIndent: null + initialize: () -> requireStylesheet 'editor.css' @@ -39,6 +41,7 @@ class Editor extends View @buildCursorAndSelection() @handleEvents() @setBuffer(new Buffer) + @autoIndent = false bindKeys: -> window.keymap.bindKeys '*:not(.editor *)', @@ -301,14 +304,24 @@ class Editor extends View @selection.selectToBufferPosition(position) insertText: (text) -> + if not @autoIndent + @selection.insertText(text) + return + + state = @lineWrapper.lineForScreenRow(@getCursorRow()).state + shouldOutdent = false + if text[0] == "\n" - tab = " " - state = @lineWrapper.lineForScreenRow(@getRow).state - indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), tab) + indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), atom.tabText) text = text[0] + indent + text[1..] + else if @buffer.mode.checkOutdent(state, @getCurrentLine(), text) + shouldOutdent = true @selection.insertText(text) + if shouldOutdent + @buffer.mode.autoOutdent(state, @buffer, @getCursorRow()) + cutSelection: -> @selection.cut() copySelection: -> @selection.copy() paste: -> @selection.insertText($native.readFromPasteboard()) From 5665fcb48c78b6c82140f6ba629ee22341f2259a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Mar 2012 13:27:47 -0800 Subject: [PATCH 06/14] Fix compiler error in Xcode 4.3 Presumably this also indicated infinite recursion, but I don't believe Atom is ever actually deallocated. --- Atom/src/Atom.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Atom/src/Atom.mm b/Atom/src/Atom.mm index 20b2eceae..d8ebe4d73 100755 --- a/Atom/src/Atom.mm +++ b/Atom/src/Atom.mm @@ -24,7 +24,7 @@ - (void)dealloc { [_hiddenWindow release]; - [self dealloc]; + [super dealloc]; } - (BOOL)isHandlingSendEvent { From a4011ef6d5ca39d427d38bff496926003e64b4e2 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 14:51:11 -0800 Subject: [PATCH 07/14] Moved default bindings from Global keymap constructor to a separate method. --- src/atom/app.coffee | 2 +- src/atom/global-keymap.coffee | 6 +++--- src/atom/window.coffee | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/atom/app.coffee b/src/atom/app.coffee index fa8f8e239..39ea52cc4 100644 --- a/src/atom/app.coffee +++ b/src/atom/app.coffee @@ -15,8 +15,8 @@ class App setupKeymap: -> @keymap = new GlobalKeymap() - $(document).on 'keydown', (e) => @keymap.handleKeyEvent(e) + @keymap.bindDefaultKeys() open: (url) -> $native.open url diff --git a/src/atom/global-keymap.coffee b/src/atom/global-keymap.coffee index 1fe11643c..ec1eaf14e 100644 --- a/src/atom/global-keymap.coffee +++ b/src/atom/global-keymap.coffee @@ -9,15 +9,15 @@ class GlobalKeymap constructor: -> @bindingSets = [] + bindDefaultKeys: -> @bindKeys "*", 'meta-n': 'newWindow' 'meta-o': 'open' $(document).on 'newWindow', => $native.newWindow() - $(document).on 'open', => + $(document).on 'open', => url = $native.openDialog() atom.open(url) if url - bindKeys: (selector, bindings) -> @bindingSets.unshift(new BindingSet(selector, bindings)) @@ -29,7 +29,7 @@ class GlobalKeymap handleKeyEvent: (event) -> event.keystroke = @keystrokeStringForEvent(event) - currentNode = $(event.target) + currentNode = $(event.target) while currentNode.length candidateBindingSets = @bindingSets.filter (set) -> currentNode.is(set.selector) candidateBindingSets.sort (a, b) -> b.specificity - a.specificity diff --git a/src/atom/window.coffee b/src/atom/window.coffee index d9d1c95cb..ddb2c5f64 100644 --- a/src/atom/window.coffee +++ b/src/atom/window.coffee @@ -15,11 +15,11 @@ windowAdditions = startup: (url) -> @setupKeymap() @attachRootView(url) - - $(window).on 'close', => + + $(window).on 'close', => @shutdown() @close() - + $(window).focus() atom.windowOpened this @@ -31,7 +31,7 @@ windowAdditions = setupKeymap: -> @keymap = new GlobalKeymap() - + @keymap.bindDefaultKeys() $(document).on 'keydown', (e) => @keymap.handleKeyEvent(e) attachRootView: (url) -> From e5f15758afc91fd490cdd53269781854a4c82d83 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 15:34:17 -0800 Subject: [PATCH 08/14] :lipstick: --- src/atom/editor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index e9f3895c5..f55f28811 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -304,7 +304,7 @@ class Editor extends View @selection.selectToBufferPosition(position) insertText: (text) -> - if not @autoIndent + unless @autoIndent @selection.insertText(text) return From a1a5d9ac75adb243451789120efffbafa9cd14bc Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 15:34:39 -0800 Subject: [PATCH 09/14] Add additional auto-indent test --- spec/atom/editor-spec.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 1905ceb74..751cb62dc 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -450,6 +450,11 @@ describe "Editor", -> editor.insertText("\n") expect(editor.buffer.getLine(5)).toEqual(" ") + it "indents cursor based on the indentation of previous line", -> + editor.setCursorBufferPosition([4, 29]) + editor.insertText("\nvar thisIsCool") + expect(editor.buffer.getLine(5)).toEqual(" var thisIsCool") + describe "when text that closes a scope entered", -> it "outdents the text", -> editor.setCursorBufferPosition([1, 30]) From f00632a96ecd4df3077dca44967fcfaa4d946fec Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 15:53:54 -0800 Subject: [PATCH 10/14] Paste uses Editor.insertText --- src/atom/editor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index f55f28811..850ec3b99 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -324,7 +324,7 @@ class Editor extends View cutSelection: -> @selection.cut() copySelection: -> @selection.copy() - paste: -> @selection.insertText($native.readFromPasteboard()) + paste: -> @insertText($native.readFromPasteboard()) foldSelection: -> @selection.fold() From fe07e45ebc0ebfaba890cfc49b11183fee1462d1 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 16:16:49 -0800 Subject: [PATCH 11/14] Refactor Ace specific code into its own adapter class. --- src/atom/ace-outdent-adaptor.coffee | 18 +++++++++++++++ src/atom/buffer.coffee | 10 --------- src/atom/editor.coffee | 34 ++++++++++++++++------------- 3 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 src/atom/ace-outdent-adaptor.coffee diff --git a/src/atom/ace-outdent-adaptor.coffee b/src/atom/ace-outdent-adaptor.coffee new file mode 100644 index 000000000..058ba8fbe --- /dev/null +++ b/src/atom/ace-outdent-adaptor.coffee @@ -0,0 +1,18 @@ +Range = require 'range' + +module.exports = +class AceOutdentAdaptor + constructor: (@buffer) -> + + getLine: (row) -> + @buffer.getLine(row) + + # We don't care where the bracket is; we always outdent one level + findMatchingBracket: ({row, column}) -> + {row: 0, column: 0} + + # Does not actually replace text, just line at range.start outdents one level + replace: (range, text) -> + start = range.start + end = {row: range.start.row, column: range.start.column + atom.tabText.length} + @buffer.change(new Range(start, end), "") diff --git a/src/atom/buffer.coffee b/src/atom/buffer.coffee index 1e94010cc..ee56034c7 100644 --- a/src/atom/buffer.coffee +++ b/src/atom/buffer.coffee @@ -105,14 +105,4 @@ class Buffer @mode = new (require("ace/mode/#{modeName}").Mode) - # API to match Ace's Document class - findMatchingBracket: ({row, column}) -> - {row: 0, column: 0} - - replace:(range, text) -> - # Only used to outdent lines - start = range.start - end = {row: range.start.row, column: range.start.column + atom.tabText.length} - @change(new Range(start, end), "") - _.extend(Buffer.prototype, EventEmitter) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 850ec3b99..13bb6896f 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -1,4 +1,5 @@ {View, $$} = require 'space-pen' +AceOutdentAdaptor = require 'ace-outdent-adaptor' Buffer = require 'buffer' Point = require 'point' Cursor = require 'cursor' @@ -33,7 +34,6 @@ class Editor extends View undoManager: null autoIndent: null - initialize: () -> requireStylesheet 'editor.css' requireStylesheet 'theme/twilight.css' @@ -304,23 +304,27 @@ class Editor extends View @selection.selectToBufferPosition(position) insertText: (text) -> - unless @autoIndent - @selection.insertText(text) - return - - state = @lineWrapper.lineForScreenRow(@getCursorRow()).state - shouldOutdent = false - - if text[0] == "\n" - indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), atom.tabText) - text = text[0] + indent + text[1..] - else if @buffer.mode.checkOutdent(state, @getCurrentLine(), text) - shouldOutdent = true + { text, shouldOutdent } = @autoIndentText(text) @selection.insertText(text) - if shouldOutdent - @buffer.mode.autoOutdent(state, @buffer, @getCursorRow()) + @autoOutdentText() if shouldOutdent + + autoIndentText: (text) -> + if @autoIndent + state = @lineWrapper.lineForScreenRow(@getCursorRow()).state + + if text[0] == "\n" + indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), atom.tabText) + text = text[0] + indent + text[1..] + else if @buffer.mode.checkOutdent(state, @getCurrentLine(), text) + shouldOutdent = true + + {text, shouldOutdent} + + autoOutdentText: -> + state = @lineWrapper.lineForScreenRow(@getCursorRow()).state + @buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer), @getCursorRow()) cutSelection: -> @selection.cut() copySelection: -> @selection.copy() From 0737529f07412f37a687d597d5bb803adb87d90d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 16:34:43 -0800 Subject: [PATCH 12/14] Auto-outdent maintains proper cursor positon. --- spec/atom/editor-spec.coffee | 2 ++ src/atom/ace-outdent-adaptor.coffee | 5 ++++- src/atom/editor.coffee | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 751cb62dc..1006255ed 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -463,6 +463,8 @@ describe "Editor", -> editor.insertText("}") expect(editor.buffer.getLine(2)).toEqual(" }") + expect(editor.getCursorBufferPosition().column).toBe 3 + describe "selection", -> selection = null diff --git a/src/atom/ace-outdent-adaptor.coffee b/src/atom/ace-outdent-adaptor.coffee index 058ba8fbe..bcad23f27 100644 --- a/src/atom/ace-outdent-adaptor.coffee +++ b/src/atom/ace-outdent-adaptor.coffee @@ -2,7 +2,7 @@ Range = require 'range' module.exports = class AceOutdentAdaptor - constructor: (@buffer) -> + constructor: (@buffer, @editor) -> getLine: (row) -> @buffer.getLine(row) @@ -13,6 +13,9 @@ class AceOutdentAdaptor # Does not actually replace text, just line at range.start outdents one level replace: (range, text) -> + {row, column} = @editor.getCursorBufferPosition() start = range.start end = {row: range.start.row, column: range.start.column + atom.tabText.length} @buffer.change(new Range(start, end), "") + @editor.setCursorBufferPosition({row, column: column - atom.tabText.length}) + diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 13bb6896f..6ccaea521 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -324,7 +324,7 @@ class Editor extends View autoOutdentText: -> state = @lineWrapper.lineForScreenRow(@getCursorRow()).state - @buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer), @getCursorRow()) + @buffer.mode.autoOutdent(state, new AceOutdentAdaptor(@buffer, this), @getCursorRow()) cutSelection: -> @selection.cut() copySelection: -> @selection.copy() From 07035788208ee45fd7f5a8498272d7ad4642f738 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 16:34:59 -0800 Subject: [PATCH 13/14] autoIndent is enabled by default. --- spec/atom/editor-spec.coffee | 2 +- src/atom/editor.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 1006255ed..86ddf9654 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -12,6 +12,7 @@ describe "Editor", -> beforeEach -> buffer = new Buffer(require.resolve('fixtures/sample.js')) editor = new Editor + editor.autoIndent = false editor.enableKeymap() editor.setBuffer(buffer) @@ -462,7 +463,6 @@ describe "Editor", -> expect(editor.buffer.getLine(2)).toEqual(" ") editor.insertText("}") expect(editor.buffer.getLine(2)).toEqual(" }") - expect(editor.getCursorBufferPosition().column).toBe 3 describe "selection", -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 6ccaea521..4c7f0f050 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -41,7 +41,7 @@ class Editor extends View @buildCursorAndSelection() @handleEvents() @setBuffer(new Buffer) - @autoIndent = false + @autoIndent = true bindKeys: -> window.keymap.bindKeys '*:not(.editor *)', From 6134d9e41e57393922e4679fb930cf6b663a0521 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Tue, 6 Mar 2012 16:48:28 -0800 Subject: [PATCH 14/14] Global Keyboard shortcuts work from spec window. --- Atom/src/Atom.mm | 3 ++- Atom/src/AtomController.h | 3 +++ Atom/src/AtomController.mm | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Atom/src/Atom.mm b/Atom/src/Atom.mm index d8ebe4d73..84acbaad8 100755 --- a/Atom/src/Atom.mm +++ b/Atom/src/Atom.mm @@ -40,7 +40,8 @@ if ([[self mainMenu] performKeyEquivalent:event]) return; - if (_clientHandler && ![self keyWindow] && [event type] == NSKeyDown) { + bool windowHandlesKeyEvents = [[[self keyWindow] windowController] handlesKeyEvents]; + if (_clientHandler && !windowHandlesKeyEvents && [event type] == NSKeyDown) { [_hiddenWindow makeKeyAndOrderFront:self]; [_hiddenWindow sendEvent:event]; } diff --git a/Atom/src/AtomController.h b/Atom/src/AtomController.h index fd630dc11..a9853c827 100644 --- a/Atom/src/AtomController.h +++ b/Atom/src/AtomController.h @@ -9,6 +9,8 @@ class ClientHandler; NSView *_webView; NSString *_bootstrapScript; NSString *_pathToOpen; + + bool _handlesKeyEvents; CefRefPtr _atomContext; CefRefPtr _clientHandler; @@ -17,6 +19,7 @@ class ClientHandler; - (id)initWithBootstrapScript:(NSString *)bootstrapScript atomContext:(CefRefPtr) context; - (id)initWithPath:(NSString *)path atomContext:(CefRefPtr)atomContext; - (id)initSpecsWithAtomContext:(CefRefPtr)atomContext; +- (bool)handlesKeyEvents; - (void)createBrowser; diff --git a/Atom/src/AtomController.mm b/Atom/src/AtomController.mm index f07edbd2a..7d3ea1450 100644 --- a/Atom/src/AtomController.mm +++ b/Atom/src/AtomController.mm @@ -29,10 +29,12 @@ - (id)initWithPath:(NSString *)path atomContext:(CefRefPtr)atomContext { _pathToOpen = [path retain]; + _handlesKeyEvents = YES; return [self initWithBootstrapScript:@"window-bootstrap" atomContext:atomContext]; } - (id)initSpecsWithAtomContext:(CefRefPtr)atomContext { + _handlesKeyEvents = NO; return [self initWithBootstrapScript:@"spec-bootstrap" atomContext:atomContext]; } @@ -56,6 +58,10 @@ CefBrowser::CreateBrowser(window_info, _clientHandler.get(), [indexURLString UTF8String], settings); } +- (bool)handlesKeyEvents { + return _handlesKeyEvents; +} + #pragma mark BrowserDelegate - (void)loadStart {