sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

`window.new_file()` sets a wrong name to the applied syntax

Open jfcherng opened this issue 4 years ago • 3 comments

Description

Similar to #3526, window.new_file() sets a wrong name to the applied syntax

image

Steps to reproduce

  1. Execute window.new_file(syntax='scope:source.json') in ST console
  2. 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

jfcherng avatar Jun 12 '21 12:06 jfcherng

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

  1. Create above file in User/
  2. 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 :(

rwols avatar Jun 20 '21 14:06 rwols

And the "syntax" key of settings() returns a bugged path

>>> view.settings().get("syntax")
'scope:source.json'

rwols avatar Jun 20 '21 14:06 rwols

Hopefully get this fixed for the sake of consistency? Or disallow window.new_file() to use scope: form syntax.

jfcherng avatar Aug 10 '23 02:08 jfcherng