obsidian-tasks icon indicating copy to clipboard operation
obsidian-tasks copied to clipboard

Show context of a task as tooltip

Open st-- opened this issue 1 year ago • 3 comments

⚠️ Please check that this feature request hasn't been suggested before.

  • [X] I searched previous Ideas in Discussions didn't find any similar feature requests.
  • [X] I searched previous Issues didn't find any similar feature requests.
  • [X] I am only requesting a single feature. Multiple changes should be split into individual requests, with links between them.
  • [X] I believe my requested feature will be generally applicable to other users, not just me: it is not uniquely tied to my personal workflow.

🔖 Feature description

In a task view, by hovering over a task, a tooltip shows up (this is already the case in 'short' mode), which displays the task's context from its source file. It shows the task's line as well as a few (1/2/configurable?) number of lines surrounding the task in the original source (preserving the full formatting such as indentation).

This tooltip could show up when hovering anywhere on a task item, or perhaps only when hovering over the backlink.

✔️ Solution

For "subtasks" (which may not necessarily have an unambiguous label, as different tasks may have equivalent subtasks), making it quick and easy to see the context will help disambiguate.

❓ Alternatives

You can (ctrl+)click on the backlink, if shown, but this incurs more overhead to switch to the new window, close it again, and to then re-find the position within the tasks list. A tooltip makes it much easier to quickly check contexts for multiple lines.

📝 Additional Context

Providing "context" in some way seems a very popular request, see e.g. https://github.com/obsidian-tasks-group/obsidian-tasks/discussions/60 which asks for showing sub-tasks as indented. Actually handling the state of "sub-task" relations would require a significant rewrite of the Tasks plugin and is unlikely to be feasible, but simply showing context when hovering over a task might already satisfy this need for at least some of the users (like myself).

See https://github.com/obsidian-tasks-group/obsidian-tasks/discussions/60#discussioncomment-1925075 for @therden's original suggestion.

st-- avatar Jan 25 '24 10:01 st--

Thanks for logging this!

I'd like to try and get as much of it fleshed out as possible whilst it's fresh in your mind @st--

What's the scope of this request?

I'm assuming that this only applies to the rendering of Tasks searches.

Probably that's what you mean by in a task view, but I just wanted have it spelled out... 😄

Thoughts on implementation

I was going to say that this had the same requirements for a core redesign as #60 and similar...

But I suppose that since Tasks knows the location of the task in its source file, it could do something like:

  • When rendering every task in the query results, re-read the file to extract the line before and the line after the line containing the task
    • This would slow down the rendering
  • Or make each Task store the source of the neighbouring task lines
    • This would increase memory requirements

What is currently shown in the tooltip:

This is an example of what is currently shown in the tooltip, when short mode is enabled:

image

It shows these fields:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/29fced073f50a9ad2655a91c2a1bc71766b6d6fd/src/Renderer/TaskLineRenderer.ts#L320-L337

Possible summary of this request

Just to check my understanding, I think that what this is saying is:

  • This request changes the rendering of the tooltip in Tasks query results in the following ways:
  • It adds to the current Tooltip the additional display of 3 markdown lines:
    • The markdown line before the task being rendered
    • The markdown line containing the task
    • The markdown line after the task
  • It requires that the tooltip is displayed in full mode as well as short mode.
    • But perhaps in full mode it would only need to show the markdown and not the field values

claremacrae avatar Jan 25 '24 10:01 claremacrae

Yeah, that sounds about right!

Yes, by "in a task view" I meant inside the rendered version of ```tasks ... ```

It only needs to get the context on hover, so for implementation I would be thinking of storing filename & line when parsing tasks, and then after rendering upon hover on a specific task, read the surrounding context from the stored filename & line. So there should not be any effect on the initial rendering pass - only on how long it takes to render the tooltip.

I'm wondering if 1 line before/after would be enough context - this would probably be good to make configurable.

I'm now thinking how easy/difficult it is to get the rendering right, so that it would correctly handle indentation etc., can you just reuse the Obsidian markdown renderer for that?

In full mode it should not render the field values (that are already shown in full).

st-- avatar Jan 25 '24 11:01 st--

It only needs to get the context on hover, so for implementation I would be thinking of storing filename & line when parsing tasks, and then after rendering upon hover on a specific task, read the surrounding context from the stored filename & line. So there should not be any effect on the initial rendering pass - only on how long it takes to render the tooltip.

Yes, that's true. I had thought that it added the text for every task it rendered, but it only adds a callback to every task, and when the user hovers over a task, the callback is invoked and it populates the tooltip.

I'm wondering if 1 line before/after would be enough context - this would probably be good to make configurable.

I always prefer to avoid making things configurable unless it's critical. The settings pane is already huge, and each new setting is more overhead in the following, forever more:

  • writing code
  • testing
  • documentation

So it can start as either 1 line either side, or 2... But note that will add a lot of height to a tooltip that is already clipped wrongly in some situations (close to headings or the edge of the Task results block, IIRC)

claremacrae avatar Jan 28 '24 21:01 claremacrae