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

Option to fold/collapse text #1869

Open
ejm554 opened this issue Jan 17, 2020 · 42 comments
Open

Option to fold/collapse text #1869

ejm554 opened this issue Jan 17, 2020 · 42 comments
Labels
🦁 need discuss the issue or PR need to discuss

Comments

@ejm554
Copy link

ejm554 commented Jan 17, 2020

Describe your feature request

Provide an option to fold/collapse text within the actual body of the document. This could be a button to the left of each heading. (Currently, folding is an option within the sidebar, but changes here do not affect the appearance of the body.)

What problem does this feature solve?

This would help the reader/writer to more easily see the document's outline. It could also be useful during the writing process to help the writer focus on the section that they are working on.

@Jocs
Copy link
Member

Jocs commented Feb 6, 2020

This implementation may be in trouble because markdown does not have such syntax to support collapsing and expanding text?Or what rules do we use to collapse text?

@Jocs Jocs added the 🦁 need discuss the issue or PR need to discuss label Feb 6, 2020
@andersennl
Copy link

andersennl commented Feb 11, 2020

@ejm554 you mean something like this?

Click This is hidden

Is this supported?

<details><summary>Click</summary>
This is hidden
</details>

@ejm554
Copy link
Author

ejm554 commented Feb 11, 2020

@ejm554 you mean something like this?

Click
This is hidden

Yes, I mean something like that.

@Jocs
Copy link
Member

Jocs commented Feb 16, 2020

@ejm554 Yes, it is supported by html block.

@larabr
Copy link

larabr commented Apr 7, 2020

How about rendering headings as being collapsible (as originally suggested)? It would just be a displayed property, no need to store such a state in the file itself.

@brainchild0
Copy link
Contributor

I think that the original posting is asking for a way to scroll through the document with body text from only one section (or a few sections) shown at one time, and only headers for the other sections.

Of course this features seems possible, but the TOC feature already shows the header outline without body text, and allows the user to jump to a section. I'm not sure how many users would find this feature beneficial.

Another idea is an optional mode in which only the selected section would be shown in the edit buffer. Obviously the whole document still would remain in application memory. The other sections still would be shown in, and could be chosen in, the TOC.

@Lednerb
Copy link

Lednerb commented May 20, 2020

How about rendering headings as being collapsible (as originally suggested)? It would just be a displayed property, no need to store such a state in the file itself.

I would also suggest to not only have headings collapsible but also codeblocks.

Background / Use case:
I'm writing documentations. Often I have quite long log outputs that I want to preserve (for example a nmap scan). Another usecase is for code snippets (50+ lines multiple times). This leads to a very long time spent on scrolling through the file for checks etc.

@jason-den
Copy link

jason-den commented Jul 16, 2020

It might be helpful to be able to collapse/expand any sub-content of a header (or sub-bullet-points base on indentation)?

Especially for long files like those awesome-collections, collapse/expand content would help you to keep the big picture in mind.

For example A simple jQuery Accordion with unlimited nesting

@snowc0de
Copy link

Hello I want to participate to this issue. I think it's very counter intuitive to get this and it is very buggy.
Something like having a "collapsed text" in the @ menu would be good.
Also the render inside the <details> tag is wrong. It only support plain text but not the lists or any markdown syntax.
Also It happens often that the last </details> break, then the whole thing doesn't work anymore.

When it breaks, the code is perceived by MarkText as:

<details>
<summary>A title</summary>
</details>

the text that is supposed to be related to the details.

Instead of

<details>
<summary>A title</summary>

the text that is supposed to be related to the details.
</details>

this is a very weird bug.

But this is a very cool feature to get implemented into marktext fully. Because it's really unstable right now, it's very hard to use it inside MarkText.

@alexysong
Copy link

This would be a very useful feature. It opens marktext for very large notes. Some people keep notes in a single file for easy searching. This kind of note files would have levels of headings, hence without folding/unfold they are impossible to work with. Emacs org-mode is suitable for this kind of job, with the option of opening the file folded to any level of headings of your choice by default. Of course, emacs can't render anything in-place so it would be wonderful to implement this in marktext.

@alexysong
Copy link

alexysong commented Oct 15, 2020

@brainchild0 It seems all other editors have this feature, the ones I've used are emacs, atom, vscode, and Zettlr (also WYSIWYG). Folding on headings, and allow opening documents folded to the level of choice, helps a lot with productivity, imo.

@brainchild0
Copy link
Contributor

@alexsong19: I am not rejecting the request, only asking whether it, as stated, or some alternative, best satisfies the underlying need, related to efficient document navigation.

Of the applications you have given as examples, only one is primarily an editor of text in natural language. The others are principally code editors, and naturally adapt the code-oriented metaphor of collapsible blocks toward general text. If they or Zettlr offer any compelling example of the requested feature, it may be considered. If the feature adds clutter to the visual field, then an option to disable it may be favorable to some users.

@alexysong
Copy link

alexysong commented Nov 12, 2020

@brainchild0 I was suggesting the option of allowing folding on headings. Of course for those who don't need it, simply disable it in settings.

IMHO, I have not found an alternative to org-mode in managing notes of median to large size (say longer than 2 letter pages of equivalent content), precisely because of easy folding/unfold. Let me explain. The following features that org-mode allows are important in a workflow without interruptions, which I'd love to have in MarkText:

  • the ability to fold/unfold on headings within the editor
  • one-keystroke folding/unfold
  • allow opening files folded
  • "upholding" the folding status (explained toward the end of this comment)

This way, you can always very quickly get to the section you would like to work on. It allows you to very quickly navigate to different sections
without moving your hands away from the keyboard
or
moving your eyes away from the editor window.

An outline view on the side of the editor also helps but

  • it would take precious space
  • you need to move your hand away from the keyboard and use the mouse.
  • you need to switch your eyesight between the outline panel and the editor. After you click on a heading in the outline view, you need to move your eyes back to the editor and do a little searching to locate the heading in our current view.

There are basically two types of notes I think people write most frequently:

Type A is a few pages note on a specific topic, just like a scientific paper (rendering in-place is a killing feature here). For this, you don't folding on headings too much.

Type B is a larger note file, recording many small items, quick thoughts, questions, memos, one-liner knowledge. For this type, folding on headings is essential. Because note files like this are not meant to be read from top to bottom, line-by-line. It's a "library of books". In a file like this, some items are a few lines, some are more; if everything is expanded, that difference in the space each item take will affect your perception, because when you navigate up and down that space information is in your brain but is useless or even detrimental to your awareness of the global structure of the file. The workflow that makes the most sense would be that the first thing you see upon opening the file is the "catalog", i.e. all headings folded to a level of your choice, then you navigate and expand on the section you would like to read/work on, with ideally one-keystroke. Each section is organized in different levels of headings "equally", equal in the sense that the contents are hidden but only the title (heading) of the item is shown. Again the length of each note item doesn't matter and it shouldn't come into play when navigating through the file.

Org-mode takes a step further by "upholding" the folding status all the time. For example, when you search within a file folded, it will temporarily expand the section of the matched result, and when you navigate away it automatically gets folded again. This workflow helps one to maintain a very clear global structure in their minds. This is designed for a reason: nothing you do unintentionally would destroy the "folding" status of the file, so your mind and the file is always subconsciously synchronized. VScode, on the other hand, does not uphold the folding state, which basically renders it not useful. After a while of working in a big note file, many sections are expanded, only leaving some folded Heading not visible (because they only occupy one line now).

The only gripe about org-mode is of course it doesn't render in-place, which won't happen anytime soon if at all because of the way emacs were developed.

@brainchild0
Copy link
Contributor

brainchild0 commented Nov 12, 2020

@alexsong19: I'm not sure I fully follow your suggestion, but it seems as though you are asking that when a document opens, it appears as a table of contents, without the body text, which would then appear for some specific section when the cursor moves over some particular header.

Am I following?

@alexysong
Copy link

alexysong commented Nov 12, 2020

I was asking for the ability to fold/unfold, the option to open files folded to the level of headings to your choice, and the editor uphold the folding status. I've edited my post to make it more clear - am I making more sense now?

@brainchild0
Copy link
Contributor

I was asking for the ability to fold/unfold, the option to open files folded to the level of headings to your choice, and the editor uphold the folding status. I've edited my post to make it more clear - am I making more sense now?

I believe that this detail has been clear from the beginning, but what remains unresolved for me is the question of what are the compelling use cases.

Yes, the current functionality offers no support for a document view that shows only headers, but this view is precisely the purpose of a table of contents, and I have yet to understand a use case which makes it important that this view appear in the main document pain rather than the auxiliary one in the side bar.

@alexysong
Copy link

One use case would be the paragraph about Type B notes in my previous comments. The ToC on the side, as I've also mentioned above, has three drawbacks:

  • it would take precious space
  • you need to move your hand away from the keyboard and use the mouse.
  • you need to switch your eyesight between the outline panel and the editor. After you click on a heading in the outline view, you need to move your eyes back to the editor and do a little searching to locate the heading in your current viewport.

To be able to conveniently fold/unfold on headings, endow you an uninterrupted workflow, in a relatively large note file. I detailed this as best as I could in the lengthy comment above.

@brainchild0
Copy link
Contributor

One use case would be the paragraph about Type B notes in my previous comments. The ToC on the side, as I've also mentioned above, has three drawbacks:

Yes I agree that these drawbacks are real, but I believe that the important question is whether they limit some common or important use case. That is, in what real-world scenario is moving the hand to the mouse from the keyboard, or switching eyesight between two panels, a serious obstacle?

Also note that keyboard shortcuts might readily be added to support navigation of the table of contents, without displaying sections as folded.

@alexysong
Copy link

That is, in what real-world scenario is moving the hand to the mouse from the keyboard, or switching eyesight between two panels, a serious obstacle?

Are you serious? In what real-world scenario does a function requiring moving hand between mouse and keyboard and moving eyes between panels and do eye searching not a problem?

@larabr
Copy link

larabr commented Nov 12, 2020

As @alexsong19 mentioned, if a document is very long I often find myself wanting to hide most of the stuff to focus on specific sections. I think this is a fairly common use case when you are dealing with notes that cover multiple topics and are somewhat scattered.
Using the TOC is an option if I need to jump to a specific section from time to time, but it's not a solution for continued reading across different sections, because "scrolling up and down" it's really much more convenient and faster (unless the document is huge, which is the problem we are addressing).

@brainchild0
Copy link
Contributor

brainchild0 commented Nov 12, 2020

Are you serious? In what real-world scenario does a function requiring moving hand between mouse and keyboard and moving eyes between panels and do eye searching not a problem?

It's inconvenient, but inevitable, generally. The question is whether and how reducing this particular inconvenience enhances the usability of the application for users broadly.

Nothing I've written is meant to argue that the feature is a bad idea, but I am still trying to understand in what way it might be considered a serious improvement.

@brainchild0
Copy link
Contributor

Using the TOC is an option if I need to jump to a specific section from time to time, but it's not a solution for continued reading across different sections, because "scrolling up and down" it's really much more convenient and faster (unless the document is huge, which is the problem we are addressing).

Would it help simply to add keyboard commands to jump to the preceding or succeeding sections?

@georgeef
Copy link

georgeef commented Apr 24, 2021

As @alexsong19 commented, an editor without efficient folding capabilities is useless for structured notes in one long file. I still edit my notes with vim in plain text mostly because it has a decent folding system, although I miss many modern features (there are also many other modern features that I don't miss).

@brainchild0 Since you are asking for a real use case, here is mine: one of my longest note files contains all notes that I keep on macOS, like system installations, system configuration, software installations and configuration, short usage guides, problems and fixes, etc. This file has been evolved over several years, and it currently contains 19,000 lines and 1,700 folds nested in up to 5 levels. The top-level contains 20 folds, one of the longest folds contains 260 immediate sub-folds (in this particular fold they are sorted alphabetically, otherwise manual search is difficult). Each fold contains one line for the open marker ("{{{" in vim) and header, and one line for the close marker ("}}}"). The fold header contains a type symbol (* for info, + for done, - for todo, etc.), a date, and a title.

Without folds it would be simply impossible to edit this file multiple times (order of hundreds or thousand) and efficiently, which means to go very fast where I want to add/modify content (a search sometimes works, but most of the times I need to go through the headers and open a few levels in order to find the correct place), to move a fold (including all its sub-folds) to another place, and to rearrange the structure quickly and without the need to calculate the level of each header.

I would switch immediately to any markdown editor if it had decent support for (in order of preference): folds, temporary split screen in order to see/edit two different parts of the file at the same time, either efficient builtin or programmable key bindings, efficient search with regular expressions (in vim with a single keystroke I can go to the next occurrence of the word under the cursor), either simple or configurable layout (in order to remove all fancy and useless decorations - marktext is perfect in this respect). To make it simpler: no fold support, no switch to a markdown editor for me.

Answers to expected questions

Q: Why don't I split a very long file into many small files?
A: Because it contains one logical unit (e.g., macOS notes). Splitting it does not make navigation faster, because then I need to go through many files, which is much worse than having everything in one file. Programmers need an IDE in order to handle big projects, I would need something equivalent, not just an editor.

Q: Why am I stuck with vim and I don't try a markdown editor?
A: I did try, I have edited a document at the size of a printed book. However, in this case the end result, the structure and the content was known to me in advance. I knew the level and the order of each header at the moment I insert it and I didn't need to rearrange anything. It is much more difficult to arrange once and then rearrange hundred times a live document which evolves over time. It shouldn't take more than muscle memory and less than a second of thinking in order to execute a rearrangement (I need my time in order to think what to change or to rearrange, not in order to execute what I thought).

@brainchild0
Copy link
Contributor

brainchild0 commented Apr 25, 2021

@georgeef: Sorry, I am missing a few details about your use case. What is the usage of three consecutive squiggly braces, and what is the meaning of the term folds, in your example? It seems you are not referring to section (as separated by section headers).

@georgeef
Copy link

georgeef commented Apr 25, 2021

@brainchild0: I assume that a section in markdown syntax is defined as a header of any level and all the content after it, up to (not including) the next header of the same or smaller level (or the end of the file). The level of a header (and its corresponding section) is the number of #s. A section can contain lower-level sections (upper level means smaller level number, lower level means bigger level number).

With the above definitions, a fold in vim is practically the same thing as a section in markdown syntax (there is a small difference, see below). For example the following markdown text:

`
some text
# section 1
text 1

## section 1.1
text 1.1

### section 1.1.1
text 1.1.1

## section 1.2
text 1.2

# section 2
## section 2.1
text 2.1
`

is equivalent to the following fold-aware text [edit: in vim]:

`
some text
{{{ section 1
text 1

{{{ section 1.1
text 1.1

{{{ section 1.1.1
text 1.1.1

}}}
}}}
{{{ section 1.2
text 1.2

}}}
}}}
{{{ section 2
{{{ section 2.1
text 2.1
}}}
}}}
`

It is often convenient to have text between two folds of the same level, e.g., say that I insert an empty line above "section 2" in the fold-aware text, such that there is a separation between"section 1" and "section 2" when they are both collapsed. Adding another empty line above "section 2" in the markdown text does not help, since it will be eaten by "section 1.2". One possible workaround would be to insert an empty header of level 1 (just a # without header text) followed by an empty line immediately above "section 2". This empty header would act as a fold end for the current section of level 1, but it would not render anything because it is empty.

The simplest implementation would be to provide folding capabilities to headers, as suggested by @ejm554. This is not the same as the <details> construct. IMHO having two different systems (heading and folding), which both try to structure the text independently, is confusing and too much implementation/interface trouble for little benefit. In most (if not all) cases, the intention of the user is to have folds consistent with the heading system, so it is simpler to just consider the terms fold and section as indistinguishable.

The TOC is not practical for very long files. In my use case the fully expanded TOC would be 1,700 lines, so it takes some considerable effort to navigate through it, and spending this effort in a separate view is destructing and inefficient, as already commented by others. What I would need is an easy way to expand/collapse headers in the main view, and a simple visual guide in order to easily distinguish which headers are expanded and which are collapsed.

The fold state could be implemented with one of the following options (ordered from minimal to full-featured):

  • [S1] Configuration option in the editor: open a file with all headers collapsed or expanded. After this the user can control the state of each individual header manually.
  • [S2] Configuration option in the editor: select the number of levels that are expanded when a file is opened (0 means all headers collapsed, -1 or some big number means all headers expanded).
  • [S3] Attribute in the beginning of a file: select the number of levels that are expanded when this file is opened (like [S2], but custom configuration per file).
  • [S4] Attribute in a header inside the file: set the default (file open) state of this header to collapsed (all lower-level sections inside it are hidden, independently of their header attributes).

[S3] and [S4] deviate from the markdown syntax, since they introduce special attributes recognizable only by one editor (all other editors/viewers will ignore these attributes and will show the file with all headers expanded).

The <details> construct could be emulated with foldable headers, at least approximately, as follows:

  • With option [S2] or [S3], the user can set the number of expanded levels and consider all lower-level headers as details, which are collapsed when the file is opened.
  • With option [S4], any header at any level can be tagged as detail.

All the above make a decent fold-aware viewer, but more is needed for a decent fold-aware editor:

  • Cut a header (section) of level N and paste it somewhere inside another section of level M. All level numbers inside the cut section are automatically incremented by M+1-N (or decremented by N-M-1), such that level N becomes M+1, level N+1 becomes M+2, etc.
  • Instead of cut-and-paste, just drag-and-drop while pressing a modifier key.
  • Split screen it order to make the transfer from one place to another easier.
  • Switch between folding mode and heading mode. In folding mode, the user thinks in terms of nested folds and there are convenience tools for the manipulation of folds, while the level numbers in the headers are updated automatically. In heading mode, the user edits the level numbers directly.

The folding mode is only an editor convenience, at the end the file is saved in standard markdown syntax.

@brainchild0
Copy link
Contributor

is equivalent to the following fold-aware text:

@georgeef: Using this analogy has really made me confused. The application is a Markdown editor. Are you discussing a case of editing a source document not formatted in Markdown?

@georgeef
Copy link

georgeef commented Apr 25, 2021

@brainchild0: as I said in my first message, I currently use vim to edit my notes. The second snippet shows how my notes appear in vim. The first snippet shows how they would be translated to markdown syntax.

The vim snippet shows more clearly the concept of folds, but with a more verbose syntax.

@brainchild0
Copy link
Contributor

The first snippet shows how they would be translated to markdown syntax.

@georgeef: I'm still missing important details of your use case. What is being translated to Markdown syntax? In what format is your file saved?

@georgeef
Copy link

georgeef commented Apr 25, 2021

@brainchild0: I don't use markdown for now (for the reasons explained in my first message), so my file is in vim syntax (second snippet) and nothing is translated. If I wanted to convert my notes to markdown, the patterns in the two snippets show how one syntax translates to the other. It doesn't matter how I would do the translation.

I am not suggesting in any way that marktext should process any other syntax than markdown. The point is if marktext could support some of the folding functionality (that I now use with vim), with files saved in pure markdown syntax. Also it doesn't matter what is the editor's internal representation of the folding structure (derived from the markdown headers), as long as it reads and saves files in markdown syntax.

@brainchild0
Copy link
Contributor

brainchild0 commented Apr 26, 2021

@georgeef: Yes, I do understand that nesting and folding is an abstraction that generalizes across languages, but it may be helpful in this discussion to keep the examples concrete, within the scope of editing Markdown files in Mark Text.

@koenlek
Copy link

koenlek commented Jul 20, 2021

+1 on this ticket. For me, these are the requests in order of priority:

  1. Foldable indented lists
  2. Foldable codeblocks
  3. Foldable headings

I agree that the state does not need to be stored in the file, it's only something to aid viewing/editing a currently opened file. I use it for example for todo lists* and often I add sub-bullet points with extra info. These sub-lists can get large, cluttering the overview, so I've I'm not actively working on some todo, I'd like to be able to fold its sublist away...

  • I tried various todo apps, but I keep coming back to plaintext/markdown for its ease of use.

@Jason5Lee
Copy link

I have a use case. When doing a quick note, I'm not sure the complete structure, so instead of using heading, I simply use indented lists, like this.

  • Point 1
    • Something related to point1
    • something related to point 1
    • Point 2, which is related to Point 1
      • Something related to point 2
      • Something related to point 2

Since TOC doesn't contain indented list details, folding is very useful for reviewing and refactoring.

@nikelborm
Copy link

I also wanted to support this idea because, for example, in Notion, I found this feature useful. And I use it a lot.
Here is how it looks like
Screenshot_20220128_234904

@PhantomPCH
Copy link

PhantomPCH commented Apr 11, 2022

I think that the option to collapse sections of text isn't just a navigational convenience, but also for cross-referencing purposes. For example, if there is a paragraph of text located high up near the beginning of the document that I wanted to refer to when writing a summary, the table of contents currently available allows me to find that section, jump to it, copy the paragraph and paste it temporarily at the bottom for easy reference while I'm editing and typing.

The problem comes when I want to refer to several areas of text in the document, above and below the section I'm editing. In this case, it would be far more convenient if I can just collapse the unnecessary sections except for the parts that I need to refer to. Another example would be if I wanted to refer to the question prompt/guide or the marking scheme located above my answer without getting distracted by the other paragraphs in my answer. In summary, this would be a feature that not only makes navigation easier, but also allows referencing multiple sections of the document at the same time without getting distracted by the rest of the text. Hope that this is a suitable use case for this feature 😊.

Just making headings collapsible would kind of make this restrictive, so I suggest maybe symbols like > or < or ^ to mark the beginning and end of a collapsible section, as well as differentiating the 'title' (the part that is shown) and 'body' (the part that is hidden). This would allow the user to collapse text in any part of the document. I understand if this isn't possible though, because I don't have that much experience in coding and markdown. Adding a "collapse all" and "expand all" option may also make it more convenient for users to reset temporary changes made to the document, for example, I can simply click "expand all" when I'm done writing my summary to read my overall answer.

@benvigano
Copy link

+1 - This is the only feature missing for me to switch to Marktext (best md editor btw)

@pencilheart
Copy link

+1
Sometimes I use the feature to fold some code I've given up on, but if something goes wrong I check and re-use them.

@MatveyM11
Copy link

+1

This feature is implemented well in other Markdown editors like Zettlr.
It's quite useful when you need to navigate among huge chunks of texts or when you have a lot of the sub-topics.

@hCKbJf6MCesgWSPH
Copy link

+1
I was looking for a open source markdown editor and this one came up often, and has 37.6k stars. The first thing I need is <details><summary>title</summary>collapsible content</details> and it's not supported..duh! I don't know if collapsible content is part of a markdown standard and if this editor only implements what's in the standard, but it should be added to both.
If the reason not to support it is that things are not visible without clicking them first, well, URL are supported and they are also not visible without clicking them first. GITHUB also supports collapsible content.

According to this, the future of this project is uncertain (also just look at the commit history and there's no other active branch).

If someone could code the support of collapsible content and add it to the Pull requests (I didn't see it there) that would certainly be appreciated by many and they, at least, could add/merge this feature themselves in the meantime.

@player340
Copy link

player340 commented Apr 22, 2023

+1

This would be so useful!

@geronimi73
Copy link

+1

1 similar comment
@trongnghia203
Copy link

+1

@nikelborm
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦁 need discuss the issue or PR need to discuss
Projects
None yet
Development

No branches or pull requests