def _focus_error_in_view(self, view, point, set_cursor=True):
if view.is_loading():
sublime.set_timeout(lambda: self._focus_error_in_view(view, point, set_cursor), 100)
return
else:
a = view.text_point(*point[0])
b = view.text_point(*point[1])
region = sublime.Region(a,b)
Debug('focus', 'Error click -> _focus_error_in_view %i, %s' % (view.id(), view.file_name()))
view.window().focus_view(view)
Debug('focus', "show_at_center, Region @pos %i, (%s -> %s)" % (region.begin(), point[0], point[1]))
view.show_at_center(region)
draw = sublime.DRAW_NO_FILL
view.add_regions('typescript-error-hint', [region], 'invalid', 'dot')
# redraw region in 50ms because selection modification will remove it
sublime.set_timeout(lambda: view.add_regions('typescript-error-hint', [region], 'invalid', 'dot'), 50)
if set_cursor:
sel = view.sel()
sel.clear()
sel.add(a)
python类DRAW_NO_FILL的实例源码
def hilite(self, query):
flags = self.calculate_flags()
regs = self.view.find_all(self.build_pattern(query), flags)
if not regs:
self.view.erase_regions('vi_search')
return
# TODO: Re-enable this.
# if State(self.view).settings.vi['hlsearch'] == False:
# return
self.view.add_regions('vi_search', regs, 'comment', '',
sublime.DRAW_NO_FILL)
# TODO: Test me.
def outline_target(self):
prefs = sublime.load_settings('Preferences.sublime-settings')
if prefs.get('vintageous_visualyank') is False:
return
sels = list(self._view.sel())
sublime.set_timeout(lambda: self._view.erase_regions('vi_yy_target'), 350)
self._view.add_regions('vi_yy_target', sels, 'comment', '', sublime.DRAW_NO_FILL)
def on_idle(self, view):
"""
"""
structure_info = self._get_structure_info(view)
linting = self.get_settings(view, "linting", True)
# linting
if linting and "key.diagnostics" in structure_info:
diagnostics = structure_info["key.diagnostics"]
self.errors = {}
for entry in diagnostics:
description = entry["key.description"]
#level = entry['key.severity']
row, col = entry["key.line"], entry["key.column"]
pos = view.text_point(row-1,col-1)
self.errors[pos] = description
view.add_regions(
"swiftkitten.diagnostics",
[Region(pos,pos+1) for pos in self.errors.keys()],
"constant",
"",
sublime.DRAW_STIPPLED_UNDERLINE | sublime.DRAW_NO_OUTLINE | sublime.DRAW_NO_FILL
)
self._update_linting_status(view)
def get_draw_style(self):
"""Get the region styling.
"""
underlined = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
style = self.get('vale_alert_style')
if style == 'solid_underline':
return sublime.DRAW_SOLID_UNDERLINE | underlined
elif style == 'stippled_underline':
return sublime.DRAW_STIPPLED_UNDERLINE | underlined
elif style == 'squiggly_underline':
return sublime.DRAW_SQUIGGLY_UNDERLINE | underlined
return sublime.DRAW_OUTLINED
def update_icons(view):
file = view.file_name()
modules = []
installed = []
other = []
result = []
if file not in data:
view.run_command('npm_install', {'action': 'initial'})
else:
modules = data[file]
for region in view.find_all(MODULE):
m = re.search(MODULE, view.substr(region))
a, b = m.span(1)
module = m.group(1)
reg = Region(a + region.begin(), b + region.begin())
if module in modules or module in CORE:
installed.append(reg)
else:
other.append(reg)
result.append(module)
flags = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE
view.add_regions('require-on', installed, 'request', ICON % 'on', flags)
view.add_regions('require-off', other, 'request', ICON % 'off', flags)
return result
def draw_t1(self, edit, view, item, indent):
created = item.get('created_utc', None)
if created is not None:
created = datetime.datetime.fromtimestamp(
created).strftime('%A, %d. %B %Y %I:%M%p')
title_start = view.size()
view.insert(edit, view.size(), '%s# [%d] [%s] %s' % (
indent[2:], item.get('score', 0), item.get('author', ''), created))
title_end = view.size()
view.insert(edit, view.size(), '\n\n')
view.add_regions(
'thread-%s-title' % (item.get('id', '')),
[sublime.Region(title_start, title_end)],
'thread-title',
'dot',
flags=sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE
)
content = wrap(unescape(item.get('body', '')).strip(), indent)
content_start = view.size()
view.insert(edit, view.size(), content)
content_end = view.size() - 1
view.insert(edit, view.size(), '\n\n')
view.add_regions(
'thread-%s-body' % item.get('id', ''),
[sublime.Region(content_start, content_end)],
'thread-body',
flags=sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.HIDE_ON_MINIMAP
)
replies = item.get('replies', {})
if isinstance(replies, dict):
for child in replies.get('data', {}).get('children', []):
self.draw_item(edit, view, child, indent + ' ')
def draw_t3(self, edit, view, item, indent):
title_start = view.size()
view.insert(edit, view.size(), '# [%s] [%5d] %s' % (
item.get('id', ''), item.get('score', 0), item.get('title', '???')))
title_end = view.size()
view.insert(edit, view.size(), '\n\n')
view.add_regions(
'thread-%s-title' % (item.get('id', '')),
[sublime.Region(title_start, title_end)],
'thread-title',
'bookmark',
flags=sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE
)
content = wrap(unescape(item.get('selftext', '')).strip(), indent)
content_start = view.size()
view.insert(edit, view.size(), content)
content_end = view.size() - 1
view.insert(edit, view.size(), '\n\n')
view.add_regions(
'thread-%s-body' % item.get('id', ''),
[sublime.Region(content_start, content_end)],
'thread-body',
flags=sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.HIDE_ON_MINIMAP
)
def on_click(self,line):
if self.is_focusing_ts_view:
Debug('focus', 'Outline.on_click: is just focusing other view > ignore')
return
if line in self.regions:
draw = sublime.DRAW_NO_FILL
self.ts_view.add_regions('typescript-definition', [self.regions[line]], 'comment', 'dot', draw)
self._focus_member_in_view(self.regions[line])
def open_view(self, view, definition):
if view.is_loading():
sublime.set_timeout(lambda: self.open_view(view, definition), 100)
return
else:
start_line = definition['min']['line']
end_line = definition['lim']['line']
left = definition['min']['character']
right = definition['lim']['character']
a = view.text_point(start_line-1, left-1)
b = view.text_point(end_line-1, right-1)
region = sublime.Region(a, b)
Debug('focus', 'Z focus view %i' % view.id())
sublime.active_window().focus_view(view)
view.show_at_center(region)
sel = view.sel()
sel.clear()
sel.add(a)
view.add_regions('typescript-definition', [region],
'comment', 'dot', sublime.DRAW_NO_FILL)
# ################################# REFACTORING ############################
def _add_regions(self):
""" Display all found Errors """
if self.view:
self.view.add_regions('tsconfig-error', self.error_regions,
'invalid', 'dot', sublime.DRAW_NO_FILL)
# ######################################################################
# ############### READ CONTENT ##########
# ######################################################################
def bp_manager(filename):
global breakpoints
V = sublime.active_window().find_open_file(filename)
if filename not in breakpoints:
breakpoints.update({filename: {}})
bps = breakpoints[filename]
yield bps
style = "string", "circle", sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
V.add_regions("bp", [get_line(V, l - 1) for l in bps], *style)
fill_view("Breakpoints", breakpoints_content())
def add_regions(self, regions):
package_name = (PLUGIN_FOLDER.split(os.path.sep))[-1]
if int(sublime.version()) >= 3000:
icon = "Packages/" + package_name + "/warning.png"
self.view.add_regions("solium_errors", regions, "keyword", icon,
sublime.DRAW_EMPTY |
sublime.DRAW_NO_FILL |
sublime.DRAW_NO_OUTLINE |
sublime.DRAW_SQUIGGLY_UNDERLINE)
else:
icon = ".." + os.path.sep + package_name + os.path.sep + "warning"
self.view.add_regions("solium_errors", regions, "keyword", icon,
sublime.DRAW_EMPTY |
sublime.DRAW_OUTLINED)
def outline_target(self):
sels = list(self._view.sel())
sublime.set_timeout(
lambda: self._view.erase_regions('vi_yy_target'), 350)
self._view.add_regions('vi_yy_target', sels, 'comment', '', sublime.DRAW_NO_FILL)
def show_tooltip_popup(self, search_result):
""" open the poup with limit of time """
pt1 = self.word_point.begin()
pt2 = self.word_point.end()
self.view.add_regions('ToolTipHelper', [sublime.Region(pt1, pt2)], 'invalid', '' , sublime.DRAW_NO_FILL)
if self.has_timeout:
# set timout to 10 seconds, in the end hide the tooltip window
sublime.set_timeout(lambda:self.hide(), self.set_timeout)
# open popup window in the current cursor
show_popup(self.view,
search_result,
location = self.location,
on_navigate=self.on_navigate,
max_width=self.max_width)
self.results_arr = []
def get_user_selection(self, sel):
""" get user selection and return her in string """
# get the whole word from this point
self.location = sel;
get_word = self.view.word(sel)
self.word_point = get_word
# pt1 = get_word.begin()
# pt2 = get_word.end()
# self.view.add_regions('ToolTipHelper', [sublime.Region(pt1, pt2)], 'invalid', '' , sublime.DRAW_NO_FILL)
# get the word in string
get_word_str = self.view.substr(get_word)
return get_word_str.strip()
def run(self, edit, command, in_vis=False):
"""Update the current view with the result of calling `undo` or `redo`.
Args:
command (str): 'undo', 'redo', or 'redo_or_repeat'.
in_vis (bool): `True` if we were called from `sublundo_next_node`.
"""
t = util.VIEW_TO_TREE[self.view.id()]['tree']
pos = 0
if command == 'undo':
buf, diff, pos = t.undo()
else:
buf, diff, pos = t.redo()
self.view.replace(edit, sublime.Region(0, self.view.size()), buf)
# Re-position the cursor.
self.view.sel().clear()
self.view.sel().add(sublime.Region(pos))
self.view.show(pos)
p = sublime.active_window().find_output_panel('sublundo')
if all([p, diff, in_vis]):
p.replace(edit, sublime.Region(0, p.size()), diff)
self.view.add_regions(
'sublundo',
[self.view.full_line(pos)],
'invalid',
'',
sublime.DRAW_NO_FILL)
def update_run_marker(window, lldb=None):
if not lldb:
for view in window.views():
view.erase_regions("run_pointer")
return
with retry():
try:
bt = lldb.get_backtrace_for_selected_thread()
if 'bt' not in bt:
for view in window.views():
view.erase_regions("run_pointer")
return
for frame in bt['bt']:
if 'file' in frame and frame['line'] != 0:
found = False
for view in window.views():
if view.file_name() == frame['file']:
location = view.line(view.text_point(frame['line'] - 1, 0))
view.add_regions("run_pointer", [location], "entity.name.class", "Packages/SublimeAnarchyDebug/images/stop_point.png", sublime.DRAW_NO_FILL)
if not view.visible_region().contains(location):
view.show_at_center(location)
if window.active_group() == 0:
window.focus_view(view)
found = True
if not found:
grp = window.active_group()
window.focus_group(0)
view = window.open_file(frame['file'] + ":" + str(frame['line']), sublime.ENCODED_POSITION)
window.focus_group(grp)
location = view.line(view.text_point(frame['line'] - 1, 0))
view.add_regions("run_pointer", [location], "entity.name.class", "Packages/SublimeAnarchyDebug/images/stop_point.png", sublime.DRAW_NO_FILL)
if not view.visible_region().contains(location):
view.show_at_center(location)
break
except xmlrpc.client.Fault:
for view in window.views():
view.erase_regions("run_pointer")
def run_coverage(self, view):
settings = find_flow_settings(view.window().project_data())
if not settings.get('show_coverage'):
return
result = None
try:
result = CLI(view).coverage()
except InvalidContext:
view.erase_regions('flow_error')
view.erase_regions('flow_uncovered')
except Exception as e:
display_unknown_error(self.view, e)
if not result:
return
regions = []
for line in result['expressions']['uncovered_locs']:
start = line['start']
end = line['end']
row = int(start['line']) - 1
col = int(start['column']) - 1
endrow = int(end['line']) - 1
endcol = int(end['column'])
regions.append(
rowcol_to_region(view, row, col, endcol, endrow)
)
view.add_regions(
'flow_uncovered', regions, 'comment', '',
sublime.DRAW_STIPPLED_UNDERLINE +
sublime.DRAW_NO_FILL +
sublime.DRAW_NO_OUTLINE
)
uncovered_count = result['expressions']['uncovered_count']
covered_count_text = 'Flow coverage: {} line{} uncovered'.format(
uncovered_count, '' if uncovered_count is 1 else 's'
)
view.set_status('flow_coverage', covered_count_text)
def add_lint_marks(view, lines, **errors):
"""Adds lint marks to view on the given lines.
"""
erase_lint_marks(view)
types = {
'warning': errors['warning_underlines'],
'illegal': errors['error_underlines'],
'violation': errors['violation_underlines'],
}
style = get_settings(view, 'anaconda_linter_mark_style', 'outline')
show_underlines = get_settings(view, 'anaconda_linter_underlines', True)
if show_underlines:
for type_name, underlines in types.items():
if len(underlines) > 0:
view.add_regions(
'anaconda-lint-underline-{}'.format(type_name), underlines,
'anaconda.underline.{}'.format(type_name),
flags=sublime.DRAW_EMPTY_AS_OVERWRITE
)
if len(lines) > 0:
outline_style = {
'solid_underline': sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE,
'stippled_underline': sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE,
'squiggly_underline': sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SQUIGGLY_UNDERLINE,
'outline': sublime.DRAW_OUTLINED,
'none': sublime.HIDDEN,
'fill': None
}
gutter_theme = get_settings(
view, 'anaconda_gutter_theme', 'basic').lower()
package_name = os.path.dirname(__file__).rsplit(os.path.sep, 3)[1]
ico_path = (
'Packages/' + package_name + '/anaconda_lib/linting/'
'gutter_mark_themes/{theme}-{type}.png'
)
for lint_type, lints in get_outlines(view).items():
if len(lints) > 0:
if get_settings(view, 'anaconda_gutter_marks', False):
if gutter_theme == 'basic':
gutter_marks = marks[lint_type]
else:
gutter_marks = ico_path.format(theme=gutter_theme,
type=lint_type)
else:
gutter_marks = ''
args = [
'anaconda-lint-outlines-{}'.format(lint_type),
lints,
'anaconda.outline.{}'.format(lint_type),
gutter_marks
]
draw_style = outline_style.get(style, sublime.DRAW_OUTLINED)
if draw_style is not None:
args.append(draw_style)
view.add_regions(*args)