-
Notifications
You must be signed in to change notification settings - Fork 700
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
Conversation
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.
XiEditor/LineCache.swift
Outdated
/// - 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 == "" |
There was a problem hiding this comment.
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.
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 |
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. |
Reuse empty views when opening a new document
…shortcuts Added selectors for xi-editor#171
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.