|
20 | 20 | # Value is a dictionary: {
|
21 | 21 | # 'paths': {path: [MessageBatch, ...]},
|
22 | 22 | # 'batch_index': (path_idx, message_idx),
|
| 23 | +# 'hidden': bool |
23 | 24 | # }
|
24 | 25 | # `paths` is an OrderedDict to handle next/prev message.
|
25 | 26 | # `path` is the absolute path to the file.
|
| 27 | +# `hidden` indicates that all messages have been dismissed. |
26 | 28 | WINDOW_MESSAGES = {}
|
27 | 29 |
|
28 | 30 |
|
@@ -157,11 +159,20 @@ def __repr__(self):
|
157 | 159 | return ''.join(result)
|
158 | 160 |
|
159 | 161 |
|
160 |
| -def clear_messages(window): |
161 |
| - """Remove all messages for the given window.""" |
162 |
| - for path, batches in WINDOW_MESSAGES.pop(window.id(), {})\ |
163 |
| - .get('paths', {})\ |
164 |
| - .items(): |
| 162 | +def clear_messages(window, soft=False): |
| 163 | + """Remove all messages for the given window. |
| 164 | +
|
| 165 | + :param soft: If True, the messages are kept in memory and can be |
| 166 | + resurrected with various commands (such as list messages, or |
| 167 | + next/prev). |
| 168 | + """ |
| 169 | + if soft: |
| 170 | + winfo = WINDOW_MESSAGES.get(window.id(), {}) |
| 171 | + winfo['hidden'] = True |
| 172 | + else: |
| 173 | + winfo = WINDOW_MESSAGES.pop(window.id(), {}) |
| 174 | + |
| 175 | + for path, batches in winfo.get('paths', {}).items(): |
165 | 176 | view = window.find_open_file(path)
|
166 | 177 | if view:
|
167 | 178 | for batch in batches:
|
@@ -241,8 +252,13 @@ def _draw_region_highlights(view, batch):
|
241 | 252 |
|
242 | 253 | def message_popup(view, point, hover_zone):
|
243 | 254 | """Displays a popup if there is a message at the given point."""
|
244 |
| - paths = WINDOW_MESSAGES.get(view.window().id(), {}).get('paths', {}) |
245 |
| - batches = paths.get(view.file_name(), []) |
| 255 | + try: |
| 256 | + winfo = WINDOW_MESSAGES[view.window().id()] |
| 257 | + except KeyError: |
| 258 | + return |
| 259 | + if winfo['hidden']: |
| 260 | + return |
| 261 | + batches = winfo['paths'].get(view.file_name(), []) |
246 | 262 |
|
247 | 263 | if hover_zone == sublime.HOVER_GUTTER:
|
248 | 264 | # Collect all messages on this line.
|
@@ -285,7 +301,7 @@ def filter_point(batch):
|
285 | 301 |
|
286 | 302 | def _click_handler(view, url, hide_popup=False):
|
287 | 303 | if url == 'hide':
|
288 |
| - clear_messages(view.window()) |
| 304 | + clear_messages(view.window(), soft=True) |
289 | 305 | if hide_popup:
|
290 | 306 | view.hide_popup()
|
291 | 307 | elif url.startswith('file:///'):
|
@@ -426,6 +442,8 @@ def _show_message(window, current_idx, transient=False, force_open=False):
|
426 | 442 | window_info = WINDOW_MESSAGES[window.id()]
|
427 | 443 | except KeyError:
|
428 | 444 | return
|
| 445 | + if window_info['hidden']: |
| 446 | + redraw_all_open_views(window) |
429 | 447 | paths = window_info['paths']
|
430 | 448 | path, batches = _ith_iter_item(paths.items(), current_idx[0])
|
431 | 449 | batch = batches[current_idx[1]]
|
@@ -482,36 +500,40 @@ def _scroll_build_panel(window, message):
|
482 | 500 | from . import opanel
|
483 | 501 | view = window.find_output_panel(opanel.PANEL_NAME)
|
484 | 502 | if view:
|
485 |
| - view.sel().clear() |
486 |
| - region = message.output_panel_region |
487 |
| - view.sel().add(region) |
488 |
| - view.show(region) |
489 |
| - # Force panel to update. |
490 |
| - # TODO: See note about workaround below. |
491 |
| - view.add_regions('bug', [region], 'bug', 'dot', sublime.HIDDEN) |
492 |
| - view.erase_regions('bug') |
| 503 | + r = message.output_panel_region |
| 504 | + view.run_command('rust_scroll_to_region', {'region': (r.a, r.b)}) |
493 | 505 |
|
494 | 506 |
|
495 | 507 | def _scroll_to_message(view, message, transient):
|
496 | 508 | """Scroll view to the message."""
|
497 | 509 | if not transient:
|
498 | 510 | view.window().focus_view(view)
|
499 | 511 | r = message.sublime_region(view)
|
500 |
| - view.sel().clear() |
501 |
| - view.sel().add(r.a) |
502 |
| - view.show_at_center(r) |
503 |
| - # TODO: Fix this to use a TextCommand to properly handle undo. |
504 |
| - # See https://github.com/SublimeTextIssues/Core/issues/485 |
505 |
| - view.add_regions('bug', [r], 'bug', 'dot', sublime.HIDDEN) |
506 |
| - view.erase_regions('bug') |
| 512 | + view.run_command('rust_scroll_to_region', {'region': (r.a, r.a)}) |
| 513 | + |
| 514 | + |
| 515 | +def redraw_all_open_views(window): |
| 516 | + """Re-display phantoms/regions after being hidden.""" |
| 517 | + try: |
| 518 | + winfo = WINDOW_MESSAGES[window.id()] |
| 519 | + except KeyError: |
| 520 | + return |
| 521 | + winfo['hidden'] = False |
| 522 | + for path, batches in winfo['paths'].items(): |
| 523 | + view = window.find_open_file(path) |
| 524 | + if view: |
| 525 | + show_messages_for_view(view) |
507 | 526 |
|
508 | 527 |
|
509 | 528 | def show_messages_for_view(view):
|
510 | 529 | """Adds all phantoms and region outlines for a view."""
|
511 |
| - window = view.window() |
512 |
| - batches = WINDOW_MESSAGES.get(window.id(), {})\ |
513 |
| - .get('paths', {})\ |
514 |
| - .get(view.file_name(), []) |
| 530 | + try: |
| 531 | + winfo = WINDOW_MESSAGES[view.window().id()] |
| 532 | + except KeyError: |
| 533 | + return |
| 534 | + if winfo['hidden']: |
| 535 | + return |
| 536 | + batches = winfo['paths'].get(view.file_name(), []) |
515 | 537 | for batch in batches:
|
516 | 538 | _show_phantom(view, batch)
|
517 | 539 | _draw_region_highlights(view, batch)
|
@@ -629,6 +651,8 @@ def list_messages(window):
|
629 | 651 | # XXX: Or dialog?
|
630 | 652 | window.show_quick_panel(["No messages available"], None)
|
631 | 653 | return
|
| 654 | + if win_info['hidden']: |
| 655 | + redraw_all_open_views(window) |
632 | 656 | panel_items = []
|
633 | 657 | jump_to = []
|
634 | 658 | for path_idx, (path, batches) in enumerate(win_info['paths'].items()):
|
@@ -1025,7 +1049,8 @@ def _save_batches(window, batches, msg_cb):
|
1025 | 1049 | path_to_batches = collections.OrderedDict()
|
1026 | 1050 | WINDOW_MESSAGES[wid] = {
|
1027 | 1051 | 'paths': path_to_batches,
|
1028 |
| - 'batch_index': (-1, -1) |
| 1052 | + 'batch_index': (-1, -1), |
| 1053 | + 'hidden': False, |
1029 | 1054 | }
|
1030 | 1055 |
|
1031 | 1056 | for batch in batches:
|
|
0 commit comments