sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

`active_view()` returns view without input focus

Open iccir opened this issue 1 month ago • 1 comments

Description of the bug

Consider the following Listener:

class Listener(sublime_plugin.EventListener):
    def on_activated(self, view: sublime.View):
        print("on_activated", view, view.window().active_view())

I would expect the view to always be equal to that returned by active_view(). I would also expect active_view() to return the view with the text cursor. However, active_view() seems to ignore text fields, console I/O panels, etc.

If I click on the console input text field, I get:

on_activated View(86) View(67)

If I pull up a Quick Panel, I see:

on_activated View(55) View(67)

Steps to reproduce

  1. Make a plugin with the above Listener example.
  2. Open the console
  3. Notice that there is a mismatch in the active views

Expected behavior

active_view() should return the active view, as indicated by the text cursor.

Actual behavior

active_view() ignores the console input fields, quick panel input field, console output, output panels, etc.

Sublime Text build number

4200

Operating system & version

macOS 14.7

(Linux) Desktop environment and/or window manager

No response

Additional information

To be clear: on_activated() is doing what I need it to do (return the View with the cursor / input focus), active_view() is not. Please do not fix this by changing the behavior of on_activated().

I recognize that changing active_view() might break existing plug-ins. Perhaps there should be an optional "include_elements" parameter that defaults to the old behavior:

def active_view(self, include_elements=False)

OpenGL context information


iccir avatar Dec 07 '25 17:12 iccir

Listeners are primarily designed to interact with normal views, only.

deathaxe avatar Dec 08 '25 07:12 deathaxe