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

Fold content on the same line as the heading #12

Closed
alehandrof opened this issue Nov 17, 2012 · 16 comments
Closed

Fold content on the same line as the heading #12

alehandrof opened this issue Nov 17, 2012 · 16 comments

Comments

@alehandrof
Copy link
Contributor

Is it possible to fold the content on the same line of the heading?

Like this:

# Heading 1 [...]
## Heading 2

Rather than like this:

# Heading 1
[...]
## Heading 2
@vovkkk
Copy link
Contributor

vovkkk commented Mar 23, 2013

Yes, just put beginning of region one less (new line); like this:

self.view.fold(sublime.Region(sublime.Region.begin(content_region) - 1,
                              sublime.Region.end(content_region)))

@demon386 what you think? the issue so old; do you prefer current behavior?

@demon386
Copy link
Owner

Thanks for the suggestion.

There's one undesirable outcome here. Let's try:

# hello world
folding the content

Folding it, and it will become:

# hello world...

Assume that this is all you have, right now you want to start a new line and type somethings new, the behavior will be weird. You may try "cmd + enter" or "ctrl + e" to try to move beyond the "...", but you can't, because they are actually in the next line.

Thus, we have to at least rewrite the behaviors of "cmd + enter" and "ctrl +e" in this case.

This style is reasonable and I know that Org-mode and FoldingText use it. FoldingText doesn't solve this as good as Org-mode. I will try to investigate and solve this problem.

@alehandrof
Copy link
Contributor Author

The default Ctrl+Enter macro is not that sophisticated: it moves the cursor to the hard EOL and then adds a newline. My pull request adds a move to the soft eol between these two, which pushes the cursor past the fold marker (if it exists), improving its handling somewhat. There are two situations it doesn't handle well, mentioned in the request.

I understand your concern, but for me, @vovkkk's code (which I incorporated in the pull), makes the folding a lot more usable. I'll have to test it some more myself to see what else might blow up :)

I'm not sure what the issue you have in mind with Ctrl+E. (Something with Vintage or OSX?)

PS. I'm still finding my way around github and this is my first pull request. Let me know if it doesn't make sense :D

@vovkkk
Copy link
Contributor

vovkkk commented Mar 24, 2013

@demon386 I press down key and cursor moves after 'those dots' (if there are no other lines) or on next header line - so no problem :)
Dunno, if it's platform specific or something, I'm on ST2 on Windows7.

Didn't look at PR yet, sorry.

@vovkkk
Copy link
Contributor

vovkkk commented Mar 24, 2013

@alehandrof I'm not sure if changing default Ctrl+Enter is good idea, you know like you used to smthng and then BAM! it ain't work in the same way for some reason.

@alehandrof
Copy link
Contributor Author

@vovkkk I hear you. The new macro is only triggered on a markdown heading and, if I've thought it through properly, it should not have any adverse effects. Assuming we all agree that pressing Ctrl+Enter on # Heading [...]
should place the caret on the next line after the fold mark. If anything, this macro is too conservative as if fails to address two edge cases.

@vovkkk
Copy link
Contributor

vovkkk commented Mar 25, 2013

@alehandrof I understand this intention: 'press one keystroke and here we go'.
But 'default' folding doesn't work this way, I mean when you fold code block ctrl+shift+[ and then ctrl+enter it adds new line before those dots. These are defaults.
We may agree or disagree if that way is right or wrong or whatever, but it's default.
And down key does the trick.

So this is only matter of two keystrokes (down key, enter) vs. one keystroke plus unexpected behavior.
I'm not insist, but imho it doesn't worth it.
Or (if my reasoning is not convince) there should be note about this feature in readme.

@alehandrof
Copy link
Contributor Author

Because:

  1. Sublime's folding is both limited and very fussy.
  2. SmartMarkdown is an extension of Sublime's folding functionality which already introduces new (and unexpected) behaviours (e.g., Shift+Tab).

I think that it's worth implementing whatever seems most reasonable for us writers of Markdown and not worry too much about what Jon is cooking up for when he's looking at C+ code :)

I rather like the Ctrl+Enter workaround, but I would prefer if it was more robust.

@demon386 suggests that that Org-Mode handles this well. I would like to try it out but I still wake up screaming from the last time I saw Emacs' UI.

@vovkkk
Copy link
Contributor

vovkkk commented Mar 27, 2013

Okay, yes, agree.

However, I'm sure that for code blocks (you have those in your mds, eh?) default ctrl+enter makes more sense, beacause you have new line after fold mark anyway.
So I made that both cases are used alehandrof#5

Thoughts?

@alehandrof
Copy link
Contributor Author

I've merged your code in the pull; it seems robust. Waiting on @demon386 to check it out.

I'm sure that for code blocks (you have those in your mds, eh?) default ctrl+enter makes more sense,

I'm not sure I understand what you mean.

@demon386
Copy link
Owner

demon386 commented Apr 1, 2013

Hey guys.

Thanks for the work. I've merged your work into the develop branch. It will go to master branch and get released eventually, I have to test it for a while and also write documentation to not confuse the current user.

Thanks again for the contribution!

@vovkkk
Copy link
Contributor

vovkkk commented Apr 2, 2013

I'm not sure I understand what you mean.

In fact, we have two types of folding:

  1. Default - possible only with indentations; including code blocks and nested lists.
  2. 'SmartMarkdown' folding which possible only with # symbol(s).

First one folds only indented lines; and you have new line or last symbol anyway:
pic 2013-04-02 17 59 07
pic 2013-04-02 17 59 29

Second one folds all stuff untill next headline or end of file.

Maybe it would be better if ctrl+enter worked indetically in all cases or maybe not; I'm personally can't decide.

BTW, @demon386 when you will test it, note that when headline is not folded and you press ctrl+enter nothing happens :) I've missed that case, noticed just now.

@alehandrof
Copy link
Contributor Author

Sorry for taking so long to respond.

@demon386 What kind of documentation do you have in mind? I'd like to help since I opened this particular can of worms :)

I took a stab at it, let me know if this is what you were thinking of:


Smart Header folding / unfolding

Pressing Tab on a header will fold the content of that section and all its subsections.

Pressing Tab on a folded header will unfold the content of that section, but keep its subsections folded.

Features/limitations:

  • Smart Folding will only work with Atx-style headers (e.g., ## Header).
  • Pressing Ctrl+Enter (or Cmd+Enter) on a folded header will insert a new line after the folded content.

If you'd find it useful, I can shape up the README directly.


@vovkkk I don't use Sublime's built-in folding much, because I don't find it that useful. I hadn't even noticed this issue. This seems buggy behavior to me. Have you seen this addressed in the forum at all?

@demon386
Copy link
Owner

Sorry for the delay, but finally got the leisure to take care of this. I've pushed to master. Thanks very much for the contribution!

@alehandrof
Copy link
Contributor Author

👍

Let me know about the docs.

Also, although I requested this feature originally, I think it was exclusively @vovkkk's code which ended up in the PR.

@demon386
Copy link
Owner

Thanks for reminding.

I'll modify readme.md to reflect his contribution. Let me check the Ctrl+Enter functionality later.

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

No branches or pull requests

3 participants