本文整理汇总了Python中sublime.Edit方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.Edit方法的具体用法?Python sublime.Edit怎么用?Python sublime.Edit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.Edit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_image_size_css
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def update_image_size_css(view: sublime.View, edit: sublime.Edit, pos: int):
"Updates image size in CSS context"
section = emmet.css_section(utils.get_content(view), pos, True)
# Store all properties in lookup table and find matching URL
props = {}
src = None
context_prop = None
if section:
for p in section.properties:
props[view.substr(p.name)] = p
# If value matches caret location, find url(...) token for it
if p.value.contains(pos):
context_prop = p
src = get_css_url(view, p, pos)
if src:
size = read_image_size(view, src)
if size:
patch_css_size(view, edit, props, size[0], size[1], context_prop)
else:
print('Unable to determine size of "%s": file is either unsupported or invalid' % src)
示例2: patch_css_size
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def patch_css_size(view: sublime.View, edit: sublime.Edit, props: dict, width: int, height: int, context_prop: dict):
width = '%dpx' % width
height = '%dpx' % height
width_prop = props.get('width')
height_prop = props.get('height')
if width_prop and height_prop:
# We have both properties, patch them
if width_prop.before < height_prop.before:
view.replace(edit, height_prop.value, height)
view.replace(edit, width_prop.value, width)
else:
view.replace(edit, width_prop.value, width)
view.replace(edit, height_prop.value, height)
elif width_prop or height_prop:
# Use existing attribute and replace it with patched variations
prop = width_prop or height_prop
data = utils.patch_property(view, prop, width, 'width') + utils.patch_property(view, prop, height, 'height')
view.replace(edit, sublime.Region(prop.before, prop.after), data)
elif context_prop:
# Append to source property
data = utils.patch_property(view, context_prop, width, 'width') + utils.patch_property(view, context_prop, height, 'height')
view.insert(edit, context_prop.after, data)
示例3: convert_to_data_url
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def convert_to_data_url(view: sublime.View, edit: sublime.Edit, region: sublime.Region):
max_size = emmet.get_settings('max_data_url', 0)
src = view.substr(region)
abs_file = None
if utils.is_url(src):
abs_file = src
elif view.file_name():
abs_file = utils.locate_file(view.file_name(), src)
if abs_file and max_size and os.path.getsize(abs_file) > max_size:
print('Size of %s file is too large. Check "emmet_max_data_url" setting to increase this limit' % abs_file)
return
if abs_file:
data = utils.read_file(abs_file)
if data and (not max_size or len(data) <= max_size):
ext = os.path.splitext(abs_file)[1]
if ext in mime_types:
new_src = 'data:%s;base64,%s' % (mime_types[ext], base64.urlsafe_b64encode(data).decode('utf8'))
view.replace(edit, region, new_src)
示例4: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit: sublime.Edit, event: Optional[dict] = None) -> None:
client = self.client_with_capability('referencesProvider')
file_path = self.view.file_name()
if client and file_path:
pos = get_position(self.view, event)
window = self.view.window()
self.word_region = self.view.word(pos)
self.word = self.view.substr(self.word_region)
# use relative paths if file on the same root.
base_dir = windows.lookup(window).get_project_path(file_path)
if base_dir:
if os.path.commonprefix([base_dir, file_path]):
self.base_dir = base_dir
document_position = text_document_position_params(self.view, pos)
document_position['context'] = {"includeDeclaration": False}
request = Request.references(document_position)
client.send_request(request, lambda response: self.handle_response(response, pos))
示例5: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit: sublime.Edit, point: Optional[int] = None) -> None:
hover_point = point or self.view.sel()[0].begin()
self._base_dir = windows.lookup(self.view.window()).get_project_path(self.view.file_name() or "")
self._hover = None # type: Optional[Any]
self._actions_by_config = {} # type: Dict[str, List[CodeActionOrCommand]]
self._diagnostics_by_config = {} # type: Dict[str, List[Diagnostic]]
if self.is_likely_at_symbol(hover_point):
self.request_symbol_hover(hover_point)
self._diagnostics_by_config = filter_by_point(view_diagnostics(self.view),
Point(*self.view.rowcol(hover_point)))
if self._diagnostics_by_config:
self.request_code_actions(hover_point)
self.request_show_hover(hover_point)
示例6: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit):
# type: (sublime.Edit) -> None
window = self.view.window()
if not window:
return
repo_path = self.repo_path
non_cached_files = get_selected_files(
self.view, repo_path, 'unstaged', 'untracked', 'merge-conflicts'
)
cached_files = get_selected_files(self.view, repo_path, 'staged')
sublime.set_timeout_async(
lambda: self.load_diff_windows(
window, # type: ignore # https://github.com/python/mypy/issues/4297
non_cached_files,
cached_files
)
)
示例7: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit: sublime.Edit):
try:
DebuggerAsyncTextCommand._run(edit)
DebuggerAsyncTextCommand._run = None
except Exception as e:
DebuggerAsyncTextCommand._run = None
raise e
示例8: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit: sublime.Edit):
caret = get_caret(self.view)
line = self.view.line(caret)
expr = emmet.evaluate_math(self.view.substr(line), caret - line.begin())
if expr:
r = sublime.Region(line.begin() + expr['start'], line.begin() + expr['end'])
self.view.replace(edit, r, str(expr['snippet']))
track_action('Evaluate Math')
示例9: update_image_size_html
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def update_image_size_html(view: sublime.View, edit: sublime.Edit, pos: int):
"Updates image size in HTML context"
tag = emmet.tag(utils.get_content(view), pos)
if tag and tag.name.lower() == 'img' and tag.attributes:
attrs = dict([(a.name.lower(), a) for a in tag.attributes])
if 'src' in attrs and attrs['src'].value:
src = utils.attribute_value(attrs['src'])
size = read_image_size(view, src)
if size:
patch_html_size(attrs, view, edit, size[0], size[1])
else:
print('Unable to determine size of "%s": file is either unsupported or invalid' % src)
示例10: patch_html_size
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def patch_html_size(attrs: dict, view: sublime.View, edit: sublime.Edit, width: int, height: int):
"Updates image size of HTML tag"
width = str(width)
height = str(height)
width_attr = attrs.get('width')
height_attr = attrs.get('height')
if width_attr and height_attr:
# We have both attributes, patch them
wr = utils.attribute_region(width_attr)
hr = utils.attribute_region(height_attr)
if wr.begin() < hr.begin():
view.replace(edit, hr, utils.patch_attribute(height_attr, height))
view.replace(edit, wr, utils.patch_attribute(width_attr, width))
else:
view.replace(edit, wr, utils.patch_attribute(width_attr, width))
view.replace(edit, hr, utils.patch_attribute(height_attr, height))
elif width_attr or height_attr:
# Use existing attribute and replace it with patched variations
attr = width_attr or height_attr
data = '%s %s' % (utils.patch_attribute(attr, width, 'width'), utils.patch_attribute(attr, height, 'height'))
view.replace(edit, utils.attribute_region(attr), data)
elif 'src' in attrs:
# At least 'src' attribute should be available
attr = attrs['src']
pos = attr.value_end if attr.value is not None else attr.name_end
data = ' %s %s' % (utils.patch_attribute(attr, width, 'width'), utils.patch_attribute(attr, height, 'height'))
view.insert(edit, pos, data)
示例11: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit: sublime.Edit):
caret = get_caret(self.view)
if self.view.substr(caret) == '<':
caret += 1
syntax_name = syntax.from_pos(self.view, caret)
if syntax.is_html(syntax_name):
ctx = emmet.get_tag_context(self.view, caret, syntax.is_xml(syntax_name))
if ctx and 'open' in ctx and 'close' in ctx:
open_tag = ctx['open']
close_tag = ctx['close']
pos = close_tag.begin() if open_tag.contains(caret) else open_tag.begin()
go_to_pos(self.view, pos)
track_action('Go to Tag Pair')
示例12: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def run(self, edit: sublime.Edit, region: tuple, result: str):
r = sublime.Region(*region)
utils.replace_with_snippet(self.view, edit, r, result)
self.view.show_at_center(r.begin())
示例13: convert_html
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def convert_html(view: sublime.View, edit: sublime.Edit, pos: int):
"Convert to/from data:URL for HTML context"
tag = emmet.tag(utils.get_content(view), pos)
if tag and tag.name.lower() == 'img' and tag.attributes:
src_attr = next((a for a in tag.attributes if a.name == 'src'), None)
# Get region of attribute value
region = src_attr and attr_value_region(src_attr)
if region:
toggle_url(view, edit, region)
示例14: convert_css
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def convert_css(view: sublime.View, edit: sublime.Edit, pos: int):
"Convert to/from data:URL for CSS context"
section = emmet.css_section(utils.get_content(view), pos, True)
if not section:
return
# Find value token with `url(...)` value under caret
for p in section.properties:
# If value matches caret location, find url(...) token for it
if p.value.contains(pos):
token = get_url_region(view, p, pos)
if token:
toggle_url(view, edit, token)
break
示例15: remove_comments
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Edit [as 别名]
def remove_comments(view: sublime.View, edit: sublime.Edit, region: sublime.Region, tokens: dict):
"Removes comment markers from given region. Returns amount of characters removed"
text = view.substr(region)
if text.startswith(tokens['start']) and text.endswith(tokens['end']):
start_offset = region.begin() + len(tokens['start'])
end_offset = region.end() - len(tokens['end'])
# Narrow down offsets for whitespace
if view.substr(start_offset).isspace():
start_offset += 1
if view.substr(end_offset - 1).isspace():
end_offset -= 1
start_region = sublime.Region(region.begin(), start_offset)
end_region = sublime.Region(end_offset, region.end())
# It's faster to erase the start region first
# See comment in Default/comment.py plugin
view.erase(edit, start_region)
end_region = sublime.Region(
end_region.begin() - start_region.size(),
end_region.end() - start_region.size())
view.erase(edit, end_region)
return start_region.size() + end_region.size()
return 0