sublime_text
sublime_text copied to clipboard
`window.new_file()` sets a wrong name to the applied syntax
Description
Similar to #3526, window.new_file() sets a wrong name to the applied syntax

Steps to reproduce
- Execute
window.new_file(syntax='scope:source.json')in ST console - Check the bottom-right corner
Expected behavior
The bottom-right corner shows JSON.
Actual behavior
The bottom-right corner shows (clipped) scope:source.json.
Environment
- Build: 4107 x64
- Operating system and version: Win10 21H1 x64
Furthermore, the syntax field of the view in a plugin is None:
import sublime_plugin
import sublime
class CreateScratchViewCommand(sublime_plugin.WindowCommand):
def run(self) -> None:
v = self.window.new_file(syntax="scope:source.json")
v.run_command("append", {"characters": '{"hello": "world"}\n'})
v.set_scratch(True)
v.set_read_only(True)
v.set_name("TEST")
class FooBarBaz(sublime_plugin.EventListener):
def on_load(self, view: sublime.View) -> None:
print("on_load")
syntax = view.syntax()
if not syntax:
print("view", view.id(), "has no syntax :(")
else:
print("view", view.id(), "has a syntax :), namely", syntax.path)
def on_activated(self, view: sublime.View) -> None:
print("on_activated")
syntax = view.syntax()
if not syntax:
print("view", view.id(), "has no syntax :(")
else:
print("view", view.id(), "has a syntax :), namely", syntax.path)
Steps to repro
- Create above file in User/
- Run
window.run_command("create_scratch_view")in the console
Expected Behavior
Prints:
view 1234 has a syntax :), namely Packages/JSON/JSON.sublime-syntax
Actual Behavior
Prints:
view 1234 has no syntax :(
And the "syntax" key of settings() returns a bugged path
>>> view.settings().get("syntax")
'scope:source.json'
Hopefully get this fixed for the sake of consistency? Or disallow window.new_file() to use scope: form syntax.