Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handlers for cloned views get called with the wrong view object #1253

Closed
evandrocoan opened this issue Jun 28, 2016 · 7 comments
Closed

Comments

@evandrocoan
Copy link

Submitting a feature or enhancement request:

1. Explain briefly what the enhancement is and why you think it would be useful.

The enhancement is to call the events 'on_selection' and 'on_modified' from cloned views.
It is useful because I work with big files as long as 7000 lines, hence I need to operate from multiple cloned views which use plugins that relies on the 'on_selection' and 'on_modified' events being called from cloned views

2. Provide any other necessary or useful information regarding your issue, such as (code) examples or related links.

This issue is related on the 'facelessuser/BracketHighlighter#356'. That plugin relies on the 'on_selection' and 'on_modified' events to work properly, however they are not being called from cloned views.

Environment

  • Operating system and version:
    • [ x ] Windows 10.
  • Sublime Text:
    • Build 3114.
@FichteFoll
Copy link
Collaborator

on_modified not being called makes kind of sense since cloned views share the same buffer, i.e. the same contents.

Selections, however, are per-view and on_selection_modified should get called for those.

Related: #8

@FichteFoll
Copy link
Collaborator

After some testing I came to the following conclusion: This is a bug! And I think we already have an issue for this, but I can't find it. (Please feel free to link it.)

The event handlers actually do get called, but with the wrong view object.

This becomes obvious with a plugin as follows:

import sublime_plugin


class SelectionChangeListener(sublime_plugin.EventListener):
    def on_modified(self, view):
        print("modified; view: {}, buffer: {}, primary: {}"
              .format(view.id(), view.buffer_id(), view.is_primary()))

    def on_selection_modified(self, view):
        print("selection_modified; view: {}, buffer: {}, primary: {}"
              .format(view.id(), view.buffer_id(), view.is_primary()))
        print(list(view.sel()))

@FichteFoll FichteFoll changed the title To call the events 'on_selection' and 'on_modified' from cloned views Event handlers for cloned views get called with the wrong view object Jun 29, 2016
@FichteFoll
Copy link
Collaborator

Via #1504, this also applies to sublime_plugin.ViewEventListener.

@evandrocoan
Copy link
Author

evandrocoan commented Nov 23, 2016

I was mistaken, acctually if you do it for 3 cloned views currently opened:

lastViewId = -1


def plugin_loaded():

    views   = None
    windows = sublime.windows()

    for window in windows:

        views = window.views()

        for view in views:

            print( "( fix_project_switch_restart_bug.py ) Calling restore_view, view id {0}".format( view.id() ) )
            restore_view( view )



def restore_view( view ):

    # Fix to the bug on the Sublime Text core, where all cloned views are called with the same
    # view object. If we do not fix this here, it would set all the cloned views to the same
    # position.
    #
    # #1253 Event handlers for cloned views get called with the wrong view object
    # https://github.com/SublimeTextIssues/Core/issues/1253
    #
    global lastViewId
    currentViewId = view.id()

    for selection in view.sel():

        print( "( fix_project_switch_restart_bug.py ) Iterating view.sel()[i].begin() {0}".format( selection ) )


    if( lastViewId != currentViewId ):

        # print( "( fix_project_switch_restart_bug.py ) Setting show_at_center to view id {0}".format( view.id() ) )
        view.show_at_center( view.sel()[0].begin() )

    lastViewId = currentViewId

You will get:

( fix_project_switch_restart_bug.py ) Calling restore_view, view id 25
( fix_project_switch_restart_bug.py ) view.sel()[i].begin() (0, 0)
( fix_project_switch_restart_bug.py ) Calling restore_view, view id 26
( fix_project_switch_restart_bug.py ) view.sel()[i].begin() (947, 947)
( fix_project_switch_restart_bug.py ) Calling restore_view, view id 29
( fix_project_switch_restart_bug.py ) view.sel()[i].begin() (300, 300)

@deathaxe
Copy link
Collaborator

deathaxe commented Jul 1, 2017

The bug still exists in 3140. Any progress? It causes all packages which use this function to fail on cloned views. Even though it does not cause crashes, it should be fixed soon. No python driven auto-completion or anything like that works for cloned views.

@deathaxe
Copy link
Collaborator

deathaxe commented Jul 1, 2017

Related or maybe duplicate of #289

@FichteFoll
Copy link
Collaborator

I knew we had one for this (see my first comment). Closing as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants