Add ability to fold Group headings #1012
Replies: 9 comments 8 replies
-
|
See #1323 - a request to fold indented tasks when viewed in reading mode. |
Beta Was this translation helpful? Give feedback.
-
|
See #1466 - another request to fold group headings. |
Beta Was this translation helpful? Give feedback.
-
|
@claremacrae this is something I'd be very keen on too; I had a look at the code, how to make it work with the obsidian-tasks/src/Renderer/QueryRenderer.ts Lines 314 to 322 in e65dd75 private async addAllTaskGroups(tasksSortedLimitedGrouped: TaskGroups, content: HTMLDivElement) {
for (const group of tasksSortedLimitedGrouped.groups) {
// If there were no 'group by' instructions, group.groupHeadings
// will be empty, and no headings will be added.
const detailsGroup = content.createEl('details');
const summaryItem = content.createEl('summary'); // or detailsGroup.createEl(...)?
// detailsGroup.appendChild(summaryItem) ?
await this.addGroupHeadings(summaryItem, group.groupHeadings);
await this.createTaskList(group.tasks, detailsGroup); // does this then create the new elements within the <details></details> tag?
}
}It's been a while that I've dealt with javascript so my implementation might be completely off, but if you think that's going in the right direction, I would be happy to try and implement this. |
Beta Was this translation helpful? Give feedback.
-
|
I've had a look at the generated HTML and asked the following in #theme-dev in Discord: I'm not sure if this is a #plugin-dev or #theme-dev question... I think it needs more CSS expertise, so will start here.... For <div>
<h5 data-heading="Later (3 tasks)">
<div class="heading-collapse-indicator collapse-indicator collapse-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
class="svg-icon right-triangle">
<path d="M3 8L12 17L21 8"></path>
</svg>
</div>
Later (3 tasks)
</h5>
</div>(The above code is the same, regardless of whether or not And Tasks generates: <h5 class="tasks-group-heading">
<p>Later (3 tasks)</p>
</h5>Should I simply rewrite the heading-creation in Tasks, to mimic those 10 or so lines of Obsidian code (and would it then work on all platforms?) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
As a very quick solution I've hacked together a working sample based on @st-- suggestion. This is no where polished enough to be used in production, but it might get this a bit further for those interested. Most importantly: this does not allow for folding of sub-levels so each level folds independently (which is not what you want) diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts
index d5a69b01..1e3bc56b 100644
--- a/src/Renderer/QueryResultsRenderer.ts
+++ b/src/Renderer/QueryResultsRenderer.ts
@@ -242,10 +242,12 @@ export class QueryResultsRenderer {
for (const group of tasksSortedLimitedGrouped.groups) {
// If there were no 'group by' instructions, group.groupHeadings
// will be empty, and no headings will be added.
- await this.addGroupHeadings(content, group.groupHeadings);
+ const detailsEl = createAndAppendElement('details', content);
+ const summaryItem = createAndAppendElement('summary', detailsEl);
+ await this.addGroupHeadings(summaryItem, group.groupHeadings);
const renderedListItems: Set<ListItem> = new Set();
- await this.createTaskList(group.tasks, content, queryRendererParameters, renderedListItems);
+ await this.createTaskList(group.tasks, detailsEl, queryRendererParameters, renderedListItems);
}
}You can use this CSS to style: details summary .tasks-group-heading {
margin: 0;
display: inline-block;
} |
Beta Was this translation helpful? Give feedback.
-
|
Here's a better solution to allow folding all levels using the diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts
index d5a69b01..ba4881ca 100644
--- a/src/Renderer/QueryResultsRenderer.ts
+++ b/src/Renderer/QueryResultsRenderer.ts
@@ -239,13 +239,34 @@ export class QueryResultsRenderer {
content: HTMLDivElement,
queryRendererParameters: QueryRendererParameters,
) {
+ // Map from nestingLevel -> parent details element
+ const levelContainers = new Map<number, HTMLElement>();
+ levelContainers.set(0, content); // level 0 groups attach to root content
+
for (const group of tasksSortedLimitedGrouped.groups) {
// If there were no 'group by' instructions, group.groupHeadings
// will be empty, and no headings will be added.
- await this.addGroupHeadings(content, group.groupHeadings);
+ let detailsEl
+ for (const heading of group.groupHeadings) {
+ if(heading.nestingLevel == 0) {
+ levelContainers.set(0, content); // level 0 groups attach to root content
+ }
+
+ // Decide where this group should be attached
+ const parentEl = levelContainers.get(heading.nestingLevel || 0) || content;
+
+ // Create details for this group
+ detailsEl = createAndAppendElement('details', parentEl);
+ const summaryItem = createAndAppendElement('summary', detailsEl);
+ await this.addGroupHeading(summaryItem, heading);
+
+ // Store this details element as the container for the *next level down*
+ levelContainers.set(heading.nestingLevel + 1, detailsEl);
+ }
+ // Add tasks inside
const renderedListItems: Set<ListItem> = new Set();
- await this.createTaskList(group.tasks, content, queryRendererParameters, renderedListItems);
+ await this.createTaskList(group.tasks, detailsEl || content, queryRendererParameters, renderedListItems);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
For others, there is a useful discussion going on in Obsidian Discord #plugin-dev channel about how to preserve the folding-state information: Thanks to @mdbraber for your work on this. For your following question of how to identify headings in the saved folding state
I am not sure, but I think that before we can answer that, we need to define the desired behaviour, and that will likely come out of exploratory testing. But here are some initial ideas - which may give you ideas for exploratory testing.
|
Beta Was this translation helpful? Give feedback.
-
|
@ilandikov has shared this with me - out-of-the-box collapsing in HTML https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details Does this work in Obsidian? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
From Discord
I'm using the Obsidian Tasks plugin and have a query like this:
Can you add a fold icon to the filenames and the headlines? It like to collapse some items when going through the list.
Beta Was this translation helpful? Give feedback.
All reactions