Hi ,
I dont find any simple example to open new text document and write some formatted text in it using Visual Studio Code API.
Please provide a small example where i can insert text.
I need it for "visual studio code Settings Sync" Extension
It depends on what you mean by formatted text and write. There are these samples
untitled scheme@jrieken Hi, how do I open a new buffer using the untitled scheme? I tried this:
var doc = vscode.window.activeTextEditor.document;
var untitledFile = doc.uri.with({
scheme: 'untitled'
});
vscode.workspace.openTextDocument(untitledFile);
But the error says the file already exists. Then I tried this:
var doc = vscode.window.activeTextEditor.document;
var untitledFile = doc.uri.with({
scheme: 'untitled',
path: ''
});
vscode.workspace.openTextDocument(untitledFile);
And the error becomes "path or authority must be set".
So how do I create an untitled buffer that triggers save file dialog when user wants to save it?
Thank you.
Try with an uri that has a scheme and path, like this Uri.parse('untitled:my/path/proposal')
@jrieken Is it possible to open a new buffer with an untitled document in it, but without specifying the path to where the file will be saved when you Save it? I want to have a new buffer opened and then when I click save, I want a Save dialog box to come up where they choose where to save it (just like a normal Untitled document). Currently with the untitled: Uri approach, you are forcing the resulting path of the file. The user of the extension has no open of picking where they want to save the file. Does that make sense?
Essentially, you know how you go use the Mouse to goto the File menu and click on New File? How do you recreate that exact action using the API?
@Jakobud please open a new issue for this and note that comments on closed issues are likely to be missed
Sure thing. Thanks,
Most helpful comment
@jrieken Is it possible to open a new buffer with an untitled document in it, but without specifying the path to where the file will be saved when you Save it? I want to have a new buffer opened and then when I click save, I want a Save dialog box to come up where they choose where to save it (just like a normal Untitled document). Currently with the
untitled:Uri approach, you are forcing the resulting path of the file. The user of the extension has no open of picking where they want to save the file. Does that make sense?Essentially, you know how you go use the Mouse to goto the File menu and click on New File? How do you recreate that exact action using the API?