def run(self, edit, payload=None, **kwargs): if not payload: return editor_utils.lock(self.view) 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 self.view.sel().clear() 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]))) else: # user changed content since last patch request: # replace whole content self.view.replace(edit, sublime.Region(0, self.view.size()), payload.get("content", "")) editor_utils.focus_view(self.view) self.view.show(self.view.sel()) # 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 identify(*args): client.send('editor-connect', { 'id': 'st%d' % sublime_ver, 'title': 'Sublime Text %d' % sublime_ver, 'icon': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABu0lEQVR42q2STWsTURhG3WvdCyq4CEVBAgYCM23JjEwy+cJC41gRdTIEGyELU7BNNMJQhUBBTUjSRdRI3GThRld+gbj2JwhuRFy5cZ3Ncd5LBwZCIIIXDlzmeZ9z4d458t9WoVB4XywWCcnn89i2TSaTIZvNEuRhJvtP0e7R6XT6VYJer8dkMmE0GrHf3uPxg1s8f+TR9ncZDocq63a7SiId6YogBqiPg8FASe43d3iz7/D7rcuP1zf4NnHxfV9yQc0CSFcEeihotVo0Gg22tzbh3SbP7lq4lzTuuHlqtZrkQlSgi8AIBZVKBc/zuH5lnc7tFX4OL/L9wOTJlsbGepFyuSwzUYERCqIXhGVZJJNJbqbP0b66DC8ucO/yedLptMzMF4S3X7JXeFWJ4Zln2LZPw9NT+BuxxQTquaw1Xl47yZ/WEr92j3PgnMBc08nlcvMF1Wo1DNW7G4aBpmnouo5pmtGyzM4K+v0+4/F4ITqdzqzAdV0cxyGVSsmpc5G/s1QqzQg+N5tNdUmJRIJ4PD4XkdTrdaQTClYDlvnHFXTOqu7h5mHAx4AvC/IhYE+6IliK2IwFWT3sHPsL6BnLQ4kfGmsAAAAASUVORK5CYII=' }) refresh_livestyle_files()
def run(self, edit, payload=None, **kwargs): if not payload: return editor_utils.lock(self.view) 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 self.view.sel().clear() 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]))) else: # user changed content since last patch request: # replace whole content self.view.replace(edit, sublime.Region(0, self.view.size()), payload.get('content', '')) editor_utils.focus_view(self.view) self.view.show(self.view.sel()) # 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)) else: logger.debug('Diff lock, waiting for response')
def respond_with_dependecy_list(data): "Returns list of requested dependency files, with their content" response = [] for file in data.get('files', []): file_data = file_reader.get_file_contents(file) if file_data: response.append(file_data) client.send('files', {'token': data['token'], 'files': response})
def respond_with_dependecy_list(data): "Returns list of requested dependency files, with their content" response = [] for file in data.get("files", []): file_data = file_reader.get_file_contents(file) if file_data: response.append(file_data) client.send("files", {"token": data["token"], "files": 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 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 respond_with_dependecy_list(data): "Returns list of requested dependency files, with their content" response = [] for file in data.get('files', []): file_data = file_reader.get_file_contents(file) if file_data: response.append(file_data) client.send('files', { 'token': data['token'], 'files': response })
def send_client_id(*args): client.send('client-id', {'id': 'sublime-text'})
def on_activated(self, view): refresh_livestyle_files() 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 send_client_id(*args): client.send("client-id", {"id": "sublime-text"})
def refresh_livestyle_files(): "Sends currently opened files, available for live update, to all connected clients" client.send('editor-files', { 'id': 'st%d' % sublime_ver, 'files': editor_utils.supported_files() })
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 on_activated(self, view): refresh_livestyle_files() if is_supported_view(view, True): client.send("initial-content", editor_utils.payload(view))
def refresh_livestyle_files(): "Sends currently opened files, available for live update, to all connected clients" client.send("editor-files", {"id": "st%d" % sublime_ver, "files": editor_utils.supported_files()})