From 0737529f07412f37a687d597d5bb803adb87d90d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 6 Mar 2012 16:34:43 -0800 Subject: [PATCH] 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()