Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Preview mode - #2205

Closed
dcunited08 wants to merge 9 commits into
atom:masterfrom
dcunited08:preview_mode
Closed

dcunited08 wants to merge 9 commits into
atom:masterfrom
dcunited08:preview_mode

Conversation

@dcunited08

Copy link
Copy Markdown

This replicates Sublime Text's semi-transient editor. It the user enables Preview Mode in settings (disabled by default) they can then quickly open files with a new open closing the last one unless they edit or save the file. Then the editor leaves preview mode and is permeant in the workspace until the user closes the tab. Please let me know anything I'm missing.

Comment thread src/editor.coffee Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What do you think about getting rid of the obj parameter? Then lines 208 and 209 could look like this

@subscribe @buffer, "contents-modified", (modified) => @disablePreview() if modified
@subscribe @buffer, "saved" => @disablePreview()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That would work, do you want me to change it or will this go in as shown above?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It would be great if you could make the change on your preview_mode branch 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I made the recommended changes.

@probablycorey

Copy link
Copy Markdown

This is pretty cool @dcunited08, I'm excited to merge it! It will need some editor specs to make sure it covers all the edge cases.

This will close atom/tree-view#3

@abe33

abe33 commented May 13, 2014

Copy link
Copy Markdown
Contributor

This is really great! It'll be nice to have a preview mode 👍

I was wondering if it was possible to also add a preview class on the editor-view and tab of a preview editor ?
It'll be a bit more work but we'll be able do differentiate visually preview editors from others.

Edit: Ignore my comment, I just forgot that the tabs was actually handled by another package, and it seems there's already a PR opened for that. I guess it's a just a matter of coordination.

@dcunited08

Copy link
Copy Markdown
Author

I think I found a few unexpected behaviors that I need to work out.

@abe33 it would be good to designate preview from standard editors.

…r closePreview() and fixed some code review changes
@dcunited08

Copy link
Copy Markdown
Author

I added some specs to editor-spec but I am unsure of how to run them. Please advise.

@abe33

abe33 commented May 14, 2014

Copy link
Copy Markdown
Contributor

@dcunited08 Using ctrl+alt+shift+S (run Atom + packages specs) or ctrl+alt+shift+P (run Atom specs only)

@dcunited08

Copy link
Copy Markdown
Author

@abe33 Thanks, I ran it twice and it froze up both times on autosave. Not sure if that is expected behavior at this point.

@probablycorey Is there anything else you would like to see?

@probablycorey

Copy link
Copy Markdown

This behavior feels odd:

  1. cmd-t open a file (editor.coffee)
  2. cmd-t open another file (cursor.coffee)

When cursor.coffee is opened editor.coffee will close. It seems like sublime only opens an editor in preview mode in special cases.

@probablycorey probablycorey self-assigned this May 16, 2014
@dcunited08

Copy link
Copy Markdown
Author

@probablycorey perhaps it would make better sense to disable the preview mode for the editor by default but enable it via a flag from tree-view. It would require a change to that repo as well but may be the best option.

@abe33

abe33 commented May 19, 2014

Copy link
Copy Markdown
Contributor

Regarding how ST behaves on cmd-t, it opens the file under selection in the select view but without creating a tab/editor for it, and if the file has a tab opened it selects it.
When the dialog is confirmed the file is opened in normal mode. And I think this is making sense, you browsed to look for a file, while browsing you get a preview (no need for the tab; you have the file name in sight in the search panel, and the preview can be useful if you have a lot of files with similar names, my_model, my_model_controller and my_model_spec for instance) and when you validate the dialog it means you want to open it, not just previewing it (you had the preview when browsing).

AFAIK the only case where an editor is opened in preview mode with a tab is when clicking on an entry in the tree view. And you really open it trough double-click.

If I were to choose which version I prefer I'd say that I would love having the file preview when the search file panel is on. But pressing Enter should open the selected file, not just opening a preview (with several panes side by side, I often open many other files as reference, and I don't expect these files to be closed when opening another file).

As for the tree view, I haven't test what your current version does but if it opens all files in preview mode I'm personally OK with that. Having a real opening on double-click could be useful for ST users wanting to switch but I don't see that as a must-have.

@lee-dohm

Copy link
Copy Markdown
Contributor

@dcunited08 listed the following methods of opening a file in the topic on Discuss:

  1. File > Open
  2. Cmd+T
  3. Open from prior session
  4. Using OS context menu
  5. Tree view

It sounds like what is being proposed are implicit methods of opening or previewing a file. Personally, I think that making all paths use the same functionality would be the least confusing for new users, but I can see the merits of separating them out. So what it sounds like the best approach suggested so far is:

  1. Anything that traditionally opens a file, such as File > Open, and opening from OS context menu, will continue to open a file
  2. Anything that traditionally is used to browse files, such as Cmd+T before a selection is made or single-clicking on an item in the Tree View, will preview a file
  3. Anything that is designed to restore prior state, such as open from prior session or File > Reopen last item, will restore the prior state ... whether open or preview

One edge case, Cmd+B browses files ... but only already open ones. If I execute the following steps:

  1. Open three more files using File > Open
  2. Click a file in the tree view
  3. Press Cmd+B
  4. Type in a string that matches one of the files from step 1 and the file from step 2

Should it match the file from step 2 as it is a buffer, even if it is in preview mode. Or should it only match the file from step 1?

@probablycorey

Copy link
Copy Markdown

I like @lee-dohm's proposal. For the first pass I might ignore restoring previewed files, unless it doesn't require much extra code.

For the cmd+b edge case, I can see arguments for either case. So I don't have a strong feeling either way.

@probablycorey

Copy link
Copy Markdown

Another interesting example of this is Visual Studio's preview tab

@abe33

abe33 commented May 22, 2014

Copy link
Copy Markdown
Contributor

👍 @lee-dohm and @dcunited08 The reasoning behind files preview seems really solid to me. As for the cmd-b case, couldn't it be deal with a setting and let users defines what should be the default?

@probablycorey The VS example is quite interesting indeed, I was thinking something alike for the panes, having kind of volatile pane items for things like markdown preview or coffee compile, etc..., basically, when the last pane item is a volatile item and is closed, the pane itself is removed (as done with cmd+k cmd+w), it would allow to trigger a command that creates a pane but having that pane removed automatically when you close the created pane item. The pane could then have a pin down toggle that prevent the pane from removal by a volatile pane item.
I don't know if this is something that was already discussed or not, but it seems to me there's a lot of similarities and probably there could be some common ground between these two things.

@lee-dohm

Copy link
Copy Markdown
Contributor

@abe33 Even when you allow something as a setting, you still need a default.

I like the idea of the auto-closing pane. Perhaps you should open a feature request for it, @abe33?

Personally, I think that Cmd+B should find both open buffers and preview buffers. I think we should not implement a setting for it at first and see what people think.

@dcunited08

Copy link
Copy Markdown
Author

@lee-dohm @abe33 @probablycorey

A few more thoughts on this:

  1. I think I am going to add a setting (and implement the code for both atom and tree-view) so that limits preview to only a single-click on the tree. After using it for several days, I found the fact I had to remember to immediately save the file or edit it once I opened it to keep it from disappearing was annoying.
  2. I do like ST3's cmd-t behavior but the viewing the files automatically isn't there in Atom yet and I think it would be a separate ask.
  3. @probablycorey The restoring of preview editors on reopening a project is automatic currently, I would have to have add code to ignore them when the state is saved. The only thing is the state saving doesn't store the fact the editor is in preview mode, which would need to be added.
  4. There is no visual representation currently of an editor being in preview-mode. I think that is necessary. VS has different colored tabs and ST3 has italics for the name. We could add a class that would allow theme editors to choose what they want to do but we should definitely include something in the two default themes.

@lee-dohm

Copy link
Copy Markdown
Contributor

@dcunited08 Re: Item 1 - If we're all in agreement that single-click on the tree is the only method of previewing (since the Cmd+T behavior support isn't there), why does there need to be a setting? Do we really think anyone is going to use the setting or are you suggesting putting it in just in case?

@probablycorey Do the metrics collected track what settings people use and how? If so, can that information be made public to help guide the future development of Atom? If not, can that be added? (And then made public, of course, 😆)

@abe33

abe33 commented May 23, 2014

Copy link
Copy Markdown
Contributor

@lee-dohm Sure, I'll have to find some time to dig this auto-closing pane feature. But I don't know yet when it'll be.

@dcunited08 Re: Item 2 - Yes, I also think this should be a separate feature, there's already a bit of delay before a buffer is actually rendered on screen, so I don't see how it can be done without impacting the search behavior.

@dcunited08 Re: Item 3 - If you want to ignore restoration of preview editors on restart can't you just prevent their serialization by returning null?
The Pane serialization already filters items that don't returns anything in their serialize method.

@dcunited08

Copy link
Copy Markdown
Author

@lee-dohm I wasn't sure we were all in agreement, I am fine with that functionality (tree-view single-click only).

@abe33 if there are no known issues with returning null, I'll do it @probablycorey ?

@probablycorey

Copy link
Copy Markdown

@dcunited08 if the serialization happens automatically I'm happy to leave that in, even if it doesn't remember if it was a preview pane after deserialization.

@lee-dohm the metrics don't track individual settings, they are incredibly generic right now.

@ddavison

Copy link
Copy Markdown
Contributor

@dcunited08

Copy link
Copy Markdown
Author

Update:

I am continuing to work on this but I am running into other oddities about closing of editors that I haven't ran into until now so I am taking it slow as it seems other items are being changed and I'll let those settle down.

@dcunited08 dcunited08 closed this May 28, 2014
@dcunited08 dcunited08 reopened this May 28, 2014
@dcunited08

Copy link
Copy Markdown
Author

Oops, didn't mean to close ;)

@ddavison

Copy link
Copy Markdown
Contributor

@dcunited08 if you need, refer to that package there.. i've got it working to open temp tabs, and recently (v.0.2.3) got it working to double click the file to open it permanently 👍

@joaoafrmartins joaoafrmartins mentioned this pull request Jun 2, 2014
@nshtg

nshtg commented Jun 14, 2014

Copy link
Copy Markdown

@dcunited08 do you need help doing this?

@nshtg

nshtg commented Jul 4, 2014

Copy link
Copy Markdown

@probablycorey
Since OP seems to be dead, would you like me to start implementing this behaviour in tabs and tree-view? We fixed all critical bugs at sublime-tabs and I have a pretty solid idea on how to implement this into the core packages.

I feel like this is more elegant anyway since it does not alter the atom/atom API in any way and just modifies the packages that profit directly from it!

@tacomilkshake

Copy link
Copy Markdown

@maschs Sounds like a good approach.

@probablycorey probablycorey removed their assignment Aug 25, 2014
@dcunited08

Copy link
Copy Markdown
Author

@maschs Sorry, I haven't had any time to look at this feel free to grab the code and run with it. My day job pushed Atom to the back burner for me.

@ahuth

ahuth commented Oct 11, 2014

Copy link
Copy Markdown

My own implementation of this is here: Preview Tabs.

It's based on events, and doesn't require any modifications to the tree or tab views.

@ddavison

Copy link
Copy Markdown
Contributor

This looks a lot cleaner than my sublime-tabs package.. nice work.

Sublime-Tabs will extend the previously existing tabs and tree view package, but this will just listen in on the events, without any extending of packages.. I like it!

@ahuth

ahuth commented Oct 11, 2014

Copy link
Copy Markdown

Thanks, @ddavison. I got a lot of use out of your package, and got inspired by it to try my hand at writing one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants