def run(self, edit, payload=None, **kwargs):
        if not payload:

        if payload.get("ranges") and payload.get("hash") == editor_utils.view_hash(self.view):
            # integrity check: editor content didn't changed
            # since last patch request so we can apply incremental updates
            for r in payload["ranges"]:
                self.view.replace(edit, sublime.Region(r[0], r[1]), r[2])

                # select last range
            last_range = payload["ranges"][-1]
            self.view.sel().add(sublime.Region(last_range[0], last_range[0] + len(last_range[2])))
            # user changed content since last patch request:
            # replace whole content
            self.view.replace(edit, sublime.Region(0, self.view.size()), payload.get("content", ""))


        # update initial content for current view in LiveStyle cache
        if is_supported_view(self.view, True):
            client.send("initial-content", editor_utils.payload(self.view))

            # unlock after some timeout to ensure that
            # on_modified event didn't triggered 'calculate-diff' event
        sublime.set_timeout(lambda: editor_utils.unlock(self.view), 10)
def next_queued(release=False):
	"Move to next queued diff request, if possible"
	if release:
		logger.debug('Release diff lock')
		_state['locked_by'] = None

	# make sure current command lock is still valid
	if _state['locked_by'] and _state['created'] < time() - wait_timeout:
		logger.debug('Waiting response is obsolete, reset')
		_state['locked_by'] = None

	if not _state['locked_by'] and _state['pending']:
		uri = _state['pending'].pop(0)
		view = editor_utils.view_for_uri(uri)
		if not view:
			# looks like view for pending diff is already closed, move to next one
			logger.debug('No view, move to next queued diff item')
			return next_queued()

		logger.debug('Send "calculate-diff" message')
		_state['locked_by'] = uri
		_state['created'] = time()
		client.send('calculate-diff', editor_utils.payload(view))
		logger.debug('Diff lock, waiting for response')
def send_unsaved_changes(view):
    fname = view.file_name()
    pristine = None
    if not fname:  # untitled file
        pristine = ""
    elif os.path.exists(fname):
        pristine = file_reader.read_file(fname)

    if pristine is not None:
        client.send("calculate-diff", editor_utils.payload(view, {"previous": pristine}))
 def on_activated(self, view):
     if is_supported_view(view, True):
         client.send("initial-content", editor_utils.payload(view))
def apply_incoming_updates(data):
    view = editor_utils.view_for_uri(data.get("uri"))
    if view:
        client.send("apply-patch", editor_utils.payload(view, {"patches": data["patches"]}))
def on_patcher_connect(*args):
    view = sublime.active_window().active_view()
    if is_supported_view(view, True):
        client.send("initial-content", editor_utils.payload(view))
def apply_incoming_updates(data):
	view = editor_utils.view_for_uri(data.get('uri'))
	if view:
		client.send('apply-patch', editor_utils.payload(view, {
			'patches': data['patches']