Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

titlebar - Change title of untitled tab in Visual Studio Code

I'm building a VS Code extension which includes changing the name/title of untitled-1 tab (unsaved file).
I tried running the below code in debugger console of extension but it didn't reflect in the editor:

vscode.workspace.textDocuments[0].fileName="myFile"

Is it not possible or am I missing something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is still (Q1 2020) not possible, but the next VSCode 1.42 will name its Untitled editors differently.

Untitled editors in VS Code are text buffers that have not yet been saved to disk.
You can leave them open for as long as you like and all text content is stored and restored between restarts.

Untitled editors were given generic names such as Untitled-1 and counting upwards.
In this release, untitled editors will use the content of the first line of the document for the editor title, and include the generic name as part of the description:

https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_42/untitled-title2.gif

Note: If the first line is empty or does not contain any words, the title will fall back to Untitled_* as before.

So while you cannot set the title yourself (still readonly fileName), technically... changing the first line of that file would be enough to change the title of said "Untitled" editor.


With VSCode 1.43 (Q1 2020), a new setting workbench.editor.untitled.labelFormat allows to control whether untitled editors should use the contents as title or not.
Possible values are content or name.
Configure 'workbench.editor.untitled.labelFormat': 'name' to get the previous behavior back where untitled editors would have a short title, such as Untitled-1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...