sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
814 stars 40 forks source link

`show_input_panel.on_cancel` get called on panel presenting not on closing #6531

Closed yaroslavyaroslav closed 2 weeks ago

yaroslavyaroslav commented 2 weeks ago

Description of the bug

on_cancel get called on presenting input view rather than on closing it.

Steps to reproduce

Consider code:

       sublime.active_window().show_input_panel(
            'Question:',
            window.settings().get('SOME') or '',  # type: ignore
            lambda user_input: cls.handle_input(user_input, region, text, view, mode, assistant, sheets),
            lambda user_input: cls.save_input(user_input, window),
            on_cancel=cls.check(),
        )

    @classmethod
    def check(cls):
        logger.debug('on_cancel')

Expected behavior

To call on_cancel on esc hit.

Actual behavior

it presents the following output on presenting input view:

DEBUG: show_input_panel hit
DEBUG: on_cancel
DEBUG: user_input: 

and nothing on esc key hit.

Sublime Text build number

4183

Operating system & version

macOS 15.2 beta

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information

No response

keith-hall commented 2 weeks ago

...but the code is invoking the check method and using it's output (None) as the value for the on cancel callback .. remove the parens and try again

yaroslavyaroslav commented 2 weeks ago

Ahh, yeah, forgot to add lambda beforehand, thanks.