From 29031260470335d13cc2cbaffcc243ee6320e786 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 19 Mar 2012 08:48:16 -0600 Subject: [PATCH] When editor is split, set same cursor position on new editor and focus it. --- spec/atom/root-view-spec.coffee | 11 ++++++++++- src/atom/editor.coffee | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index 84cc96311..4f47f64d5 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -1,6 +1,7 @@ $ = require 'jquery' fs = require 'fs' RootView = require 'root-view' +Buffer = require 'buffer' describe "RootView", -> rootView = null @@ -34,12 +35,14 @@ describe "RootView", -> describe "split editor panes", -> describe "when split-right is triggered on the editor", -> - it "places the a new editor to the right of the current editor in a .horizontal div, and focuses the new editor", -> + fit "places the a new editor to the right of the current editor in a .horizontal div, and focuses the new editor", -> rootView.attachToDom() expect(rootView.find('.horizontal')).not.toExist() editor1 = rootView.find('.editor').view() + editor1.setBuffer(new Buffer(require.resolve 'fixtures/sample.js')) + editor1.setCursorScreenPosition([3, 2]) editor1.trigger 'split-right' expect(rootView.find('.horizontal')).toExist() @@ -47,6 +50,12 @@ describe "RootView", -> expect(rootView.find('.horizontal .editor:eq(0)').view()).toBe editor1 editor2 = rootView.find('.horizontal .editor:eq(1)').view() expect(editor2.buffer).toBe editor1.buffer + expect(editor2.getCursorScreenPosition()).toEqual [3, 2] + expect(editor1).toHaveClass 'split' + expect(editor2).toHaveClass 'split' + + expect(editor1.has(':focus')).not.toExist() + expect(editor2.has(':focus')).toExist() # insertion reflected in both buffers editor1.buffer.insert([0, 0], 'ABC') diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index b7b0f0b86..c5a5ab3a0 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -38,7 +38,7 @@ class Editor extends View autoIndent: null lineCache: null - initialize: () -> + initialize: ({buffer}) -> requireStylesheet 'editor.css' requireStylesheet 'theme/twilight.css' @id = Editor.idCounter++ @@ -46,7 +46,7 @@ class Editor extends View @bindKeys() @buildCursorAndSelection() @handleEvents() - @setBuffer(new Buffer) + @setBuffer(buffer ? new Buffer) @autoIndent = true bindKeys: -> @@ -404,8 +404,8 @@ class Editor extends View horizontal = $$ -> @div class: 'horizontal' horizontal.insertBefore(this).append(this.detach()) - editor = new Editor - editor.setBuffer(@buffer) + editor = new Editor({@buffer}) + editor.setCursorScreenPosition(@getCursorScreenPosition()) @after(editor) @addClass 'split' editor.addClass('split')