Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse empty views when opening a new document #171

Merged
merged 2 commits into from
Mar 2, 2017

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Mar 1, 2017

This fixes another small regression from the document model changes.

I'm not totally in love with this fix; it involves stashing state in the app delegate at one point, which feels kind of gross. If someone has a cleaner approach, I'd be happy to try it.

N.B. This doesn't work with files opened from the Open Recent > menu, which uses different API, and would be hackier. We can revisit at some point.

I'm starting to develop a better understanding of the NSDocument architecture, which is giving me a stronger sense of its limitations, and of the assumptions it makes which don't really hold true for us. This becomes clearest when I think about split windows.

This is a naive implementation of this functionality. In the view
controller, we intercept all calls to `openDocument:`, and check to see
if our current document is empty. If it is, we save a reference to it in the app
delegate. We check this reference when opening a document, and reuse
existing windows if appropriate.

This does not currently cover the 'recent documents' menu, which has a
different implementation; it calls the application delegate's
application:openFile: method.
@cmyr cmyr mentioned this pull request Mar 1, 2017
/// - Note: An empty line cache will still contain a single empty line, this
/// is sent as an update from the core after a new document is created.
var isEmpty: Bool {
return lines.count == 1 && lines[0]?.text == ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A case can be made this should return true if lines.count == 0 as well. Unlikely to happen much in practice, but maybe could happen when startup / file opening is scripted.

@raphlinus
Copy link
Member

Thanks for fixing it. I agree it's not pretty, but am inclined to merge it sooner and do cleanup later.

Regarding the global questions around NSDocument: to me, whether we use NSDocument or not is still an open question. I'm not clear on exactly how much benefit we get from it that we can't get reasonably straightforward by calling the lower-level Cocoa methods directly, and it does seem we have to work around its inbuilt behavior. I'm open to both choices, just wish I had more concrete evidence either way.

Happy to merge this, but will give you a chance to change the lines == 0 behavior. Thanks!

@cmyr
Copy link
Member Author

cmyr commented Mar 2, 2017

Pushed a little fix.

Yea, I'm coming around a little bit on the NSDocument stuff. For the time being I think it helps make a few things simpler, but I strongly suspect we would want to move away from it at some point. I'm happy to at least understand why this is the case now, though.

@raphlinus raphlinus merged commit aea36f4 into xi-editor:master Mar 2, 2017
@cmyr cmyr deleted the fix-open-behaviour branch March 2, 2017 21:40
lord pushed a commit to lord/xi-editor that referenced this pull request Oct 31, 2018
Reuse empty views when opening a new document
lord pushed a commit to lord/xi-editor that referenced this pull request Oct 31, 2018
lord pushed a commit to lord/xi-editor that referenced this pull request Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants