Sublime Forum

Is it possible to prevent paste when selected points not equal clipborad lines

#1

Sometimes when I execute a multipoint edit, I select many points, for example 1000 points, but only have 999 lines on clipborad, this will cause a high CPU problem and a bad result.

I want to write a plugin to check if len(edit_points) == len(clipborad.split("\n")), and warn/prevent paste before it really do it, but can’t find an API function similar to ''on_paste" or “on_pre_modified”, and not sure which function do things like “len(edit_points)”.

Please help, thanks!

0 Likes

#2

You can get the number of selections via len(view.sel()) for the view you’re pasting into and you can use sublime.get_clipboard() to capture what’s currently on the clipboard.

Probably the easiest way to do what you want would be to define your own custom command that performs the check for you, and then use view.run_command("paste") to get the regular paste command to run, possibly prompting you first. Then you can bind your custom command to the same key as the normal paste command to override it so your command runs instead.

2 Likes

#3

Sorry for the late response, I didn’t recieve a reminder mail.

Your method is very smart, I will finish it and share it here. Thank you!

0 Likes

#4

You could start from this plugin that does a similar thing:

0 Likes