improved duplicates search in python extract method

according to PY-9639 Extract method: Replace Duplicates: search duplicates by code tree, not by exact text match
fixed PY-10995 Wrapping on right margin deletes code with slashes at the end of miltiline statements.

If we didn't process auto-formatted events from document - document could be broken by replacement.
Do not insert replacement string to the broken textrange
fixed PY-10995 properly, fixed broken test

we can skip formatting events in case of current string ends with spaces
fixed NPE
Merge remote-tracking branch 'origin/131' into 131