Since we do not load documents before the user selects them, e.g. after session restore or when opening multiple documents, it makes sense to have both an isOpen and isLoaded property, the former means “is shown somewhere in the UI” and would make it appear (e.g. in file browser) with close button etc., whereas the latter means that data has been loaded from disk, and we can safely access the buffer.
Since document_t is now a thin wrapper and OakDocument does its own tracking to ensure we do not create multiple documents for the same path, we no longer need document_t to take care of this.
The backup timer is retaining our document so the document would live for up to two seconds after it was closed, this was mainly a problem for untitled documents, as it meant the next new untitled document created would get a display name of “untitled n”.
This is because we had the initializer search for the backup and fail (return nil) when no backup was found, but in that case, dealloc would be called on the (uninitialized) object, which would unregister the document, but the document had never been registered, hence the assertion failure (about only unregistering previously registered documents).
This method is called by the matchesForString:options: which can be called from a background thread.
Though we should revise this solution later to introduce proper locking on the buffer (and possibly path) instance variable to guarantee thread safety.
The add/remove functions are called when opening/closing documents, in TextMate this happens in the main thread, but not when executing the tests. With the mutex, it should now be safe to call the functions from multiple threads at the same time although if file system changes are actually observed, the callback will be executed on the main thread.
Currently all OakDocument factory methods goes via the document controller but it would probably be better to move these methods to the document controller so that all document creation happens via the controller (unless one wants to opt out of the services provided, e.g. documents used with the bundle editor and commit window do not need to be “tracked”).
This is just to limit the functions that create new documents.
Also make initWithPath: and untitledCount: available in OakDocument’s private interface.
This would happen when creating a document with content and never opening and closing that document, so our buffer would never be deleted (previously deleted when closing a document), and the buffer callback previously held a strong reference to our document.
While we want to show the font scale factor as a percentage in the UI, internally, we should represent it as a CGFloat, which is more consistent with the NSFont APIs and makes interacting with them easier.
Previously this would be a no-op basically bringing the undo stack out of sync and making TextMate prone to crashing.
We create an undo group when reloading document changes and here we do not create a document editor, hence when this happened for unselected tabs (which currently have no document editor), the undo stack was brought out of sync.