Myriad-Dreamin / tinymist

Tinymist [ˈtaɪni mɪst] is an integrated language service for Typst [taɪpst].
https://myriad-dreamin.github.io/tinymist
Apache License 2.0
278 stars 11 forks source link

feat: add font list export panel in summary tool #322

Closed 7sDream closed 2 weeks ago

7sDream commented 3 weeks ago

This PR adds a "Copy" icon to the top right corner of the font list card, in the VSCode extension's summary page:

icon

Clicking it opens a font list export panel, which can export the list of fonts as plain text:

fontlist

By default, only the paths of external font files are exported.

The options above can control whether to include Typst built-in fonts and whether to add extra information such as font names:

fullinfo

Click the "Copy" button at the bottom to perform the copy.


This feature fully from a personal need of mine. Upon discovering that tinymist already had a feature of showing document font lists, I think implement it here may save my coding time(And it's true).

If the author also finds this feature useful, I am more than happy to polish the code based on review comments.

If you feel this feature is not suitable for the tinymist extension, please feel free to close the PR.

Myriad-Dreamin commented 3 weeks ago

It is fine to add such a feature, but I will suggest that we should provide more programmatical way to make it. We could add a command that expose the entire summary as a json file, which can be read by programs friendly.

7sDream commented 3 weeks ago

For simple needs (specifically, extract all font files used in the document from my font library), a plain text file with one font per line is actually easier to handle. If summary JSON is the only option, users would have to write code to process it themselves. But not everyone using Typst to write content is a technical person, right?

If the user is tech-savvy and requires information beyond just a list of font files, the JSON format is indeed a better (and more feature-rich) option. I'll see if I can add that functionality along the way.

Myriad-Dreamin commented 3 weeks ago

For simple needs (specifically, extract all font files used in the document from my font library), a plain text file with one font per line is actually easier to handle. If summary JSON is the only option, users would have to write code to process it themselves. But not everyone using Typst to write content is a technical person, right?

Let us think of our possible workflow:

  1. we finish writing document.
  2. we get all used fonts for bundling these fonts along with new release.
  3. we update the document.
  4. do step 2 again.

The boring work emerges at the step 4. This should mean that we have to open the summary page, and click the button for a list of used fonts, and update the font bundle according to the list. Therefore, it should be better to have some pipeline to make life easier, like that:

// tasks.json
{
  { name: "update-font-bundle", steps: [
    { "command": "shell", args: ["myscript ${input:fontList}"], "inputs": [
    {
      "id": "fontList",
      "type": "command",
      "command": "tinymist.getSummary",
      "args": ["${file}"]
    } },
  ] }
}

I understand you worries, but I still prefer to provide these information without having to perform any action in the UI. If it is hard to use by non-technical people, they can require some specialized commands, e.g. one that outputs a list of used fonts separated by newline.

7sDream commented 3 weeks ago

Very reasonable.

Given my limited experience in developing VSCode extensions, particularly with the commands aspect, I prefer to avoid hastily writing this feature, which may mess the codebase up.

For now, I can continue using my branch locally, and will eagerly anticipate the landing of this extension command in the future.

Myriad-Dreamin commented 3 weeks ago

I rethink it a bit, and make a small summary (todo list) from above discussion.


This PR can be merged with some minor changes. The current implementation doesn't look bad but I would like to change it a bit.

7sDream commented 3 weeks ago

Wow, thanks for the clear summary list.

I can make these nice changes, but I've been occupied with other daily work things lately.

I'll likely come back to it in a few days!

7sDream commented 3 weeks ago

Changes:

Screenshot:

Things for discussion:

  1. The default appearance of select[multiple] is a multi-row box. Even withsize: 1, it seems less aesthetically pleasing when displayed inline. Moreover, it requires holding down Ctrl/Command for multiple selections, which seems somewhat cumbersome. So, I temporarily still display the location filter as several input[type="checkbox"]. Any better options here? Would it be worth implementing a combo box with dropdown checkboxes specially for this?
  2. About the export command, do we only need to support JSON format for now? I briefly looked at VSCode's extension command documentation last night, and I think I can add it in this PR, after we finish the GUI part.
Myriad-Dreamin commented 2 weeks ago

The default appearance of select[multiple] is a multi-row box. Even with size: 1, it seems less aesthetically pleasing when displayed inline. Moreover, it requires holding down Ctrl/Command for multiple selections, which seems somewhat cumbersome. So, I temporarily still display the location filter as several input[type="checkbox"]. Any better options here? Would it be worth implementing a combo box with dropdown checkboxes specially for this?

I think it is already nice. Location with [ ] FS [ ] Memory allows us to select both or neither, which looks more flexible. This will not block merging.

About the export command, do we only need to support JSON format for now? I briefly looked at VSCode's extension command documentation last night, and I think I can add it in this PR, after we finish the GUI part.

I personally think export a csv by command is not quite useful, so we don't have to add a format option to the export command. When one makes some scripting, some input in json format is usually better than one in csv format.

Myriad-Dreamin commented 2 weeks ago

I tested locally. It looks pretty well.