Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear undo stack on every panel mutation #1841

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion plugin/core/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def mutable(view: sublime.View) -> Generator:
view.set_read_only(True)


def clear_undo_stack(view: sublime.View) -> None:
clear_undo_stack = getattr(view, "clear_undo_stack", None)
if not callable(clear_undo_stack):
return
# The clear_undo_stack method cannot be called from within a text command...
sublime.set_timeout(clear_undo_stack)


class WindowPanelListener(sublime_plugin.EventListener):

server_log_map = {} # type: Dict[int, List[Tuple[str, str]]]
Expand Down Expand Up @@ -112,7 +120,6 @@ class LspClearPanelCommand(sublime_plugin.TextCommand):
"""
A clear_panel command to clear the error panel.
"""

def run(self, edit: sublime.Edit) -> None:
with mutable(self.view):
self.view.erase(edit, sublime.Region(0, self.view.size()))
Expand All @@ -133,6 +140,7 @@ def run(self, edit: sublime.Edit, characters: Optional[str] = "") -> None:
# Clear the selection
selection = self.view.sel()
selection.clear()
clear_undo_stack(self.view)


def ensure_server_panel(window: sublime.Window) -> Optional[sublime.View]:
Expand Down Expand Up @@ -182,3 +190,4 @@ def run(self, edit: sublime.Edit, window_id: int) -> None:
erase_region = sublime.Region(0, last_region_end)
if not erase_region.empty():
self.view.erase(edit, erase_region)
clear_undo_stack(self.view)