Closed Enteleform closed 8 years ago
Works for me.
import sublime_plugin
class TestCommandCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
from CSScheme.my_sublime_lib.edit import Edit
with Edit(view) as e:
e.replace(view.sel()[0], "replacement")
You are not supposed to use the Edit
constructor in any other way than a with statement.
Your sample code is also very incomplete.
You are not supposed to use the Edit constructor in any other way than a with statement.
Your sample code is also very incomplete
I figured it would be enough for you understand how I was trying to implement it, and judging by your comment above, it seems you did :smile:
Looks like there may have been some misunderstanding on my part.
@ the ST recursive edit issues
thread; I posted this, which I assumed your response was in reference to.
I felt like the with
implementation of the original Edit.py
added unnecessary bulk to my code, so I ended up creating my own Edit.py
; which can be seen in conjunction with a full implementation @ my MatchReplace proof of concept.
Okay.
I do not agree with the design decisions you made for your edit.py modifications, so I will not be incorporating them into my code.
"Edits" serve the purpose to group modifications into one undo step and the way you handle it (each modification becomes its own step) defeats the purpose of that entirely. This is why we need the with
statement construct or callback method: To explicitly close the edit once we're done with it, i.e. end the TextCommand.
Good info. I'll probably end up reverting to the with
method.
What improvements does your version of Edit.py
offer over the original by linuxbochs?
It should be obvious from the docstring, but iirc:
Edit.call(view, cb)
classmethod, which is a shorthand for with Edit(view) as e: e.callback(cb)
(or similar)view.size()
in the with block would yield wrong results because the actual actions are applied after the with
block is closed. Or you use the Edit.call
variant.
as mentioned at [Solved] issue using “edit” objects recursively
Info:
ST Version: Stable Channel, Build 3103 OS: Windows 10 Pro (64-bit), Build 10586
Error:
@ MyPlugin.py:
the above code works with my modified version of edit.py