закрытие вкладки> перейти к предыдущему отредактированному - PullRequest
0 голосов
/ 24 сентября 2018

При закрытии вкладки в sublimetext3 она всегда возвращает меня к левой, тогда как на sublimetext2 меня переводили на ранее открытую (не обязательно левую).

Такое поведение былоочень удобно в sublimetext2, потому что он создал некую историю, которую легко было просмотреть, просто последовательно закрывая вкладки.

Есть ли для этого настройка в sublimetext3?

Шаги для воспроизведения

  1. У меня открыто 3 вкладки, и активна третья: enter image description here
  2. Теперь я иду и редактирую2-й: enter image description here
  3. Я закончил и решил закрыть 2-ую вкладку: enter image description here

FAIL: я не вернусь к ранее отредактированному: 3-й

1 Ответ

0 голосов
/ 25 сентября 2018

Нет настроек для этого.Однако, поскольку это может быть сделано с помощью плагина, и я хотел бы сохранить свои навыки написания плагина на пустом месте, я написал его для вас.

Он называется FocusMostRecentTabCloser, и код приведен ниже и в этом GitHub Gist .

Чтобы использовать его, сохраните его как FocusMostRecentTabCloser.py где-то в структуре каталога Packages и назначьте ключи для команды focus_most_recent_tab_closer.например,

{"keys": ["ctrl+k", "ctrl+w"], "command": "focus_most_recent_tab_closer"},

Я не тестировал его всесторонне, и для него требуется Sublime Text 3, сборка 3024 или более поздняя версия (но это уже довольно давно).

Ответ с комментарием, если есть ошибки иЯ посмотрю, что я могу сделать.

# MIT License

import sublime
import sublime_plugin
import time

LAST_FOCUS_TIME_KEY = "focus_most_recent_tab_closer_last_focused_time"

class FocusMostRecentTabCloserCommand(sublime_plugin.TextCommand):
    """ Closes the focused view and focuses the next most recent. """

    def run(self, edit):

        most_recent = []
        target_view = None
        window = self.view.window()

        if not window.views():
            return

        for view in window.views():
            if view.settings().get(LAST_FOCUS_TIME_KEY):
                most_recent.append(view)

        most_recent.sort(key=lambda x: x.settings().get(LAST_FOCUS_TIME_KEY))
        most_recent.reverse()

        # Target the most recent but one view - the most recent view
        # is the one that is currently focused and about to be closed.

        if len(most_recent) > 1:
            target_view = most_recent[1]

        # Switch focus to the target view, this must be done before
        # close() is called or close() will shift focus to the left
        # automatically and that buffer will be activated and muck
        # up the most recently focused times.

        if target_view:
            window.focus_view(target_view)

        self.view.close()

        # If closing a view which requires a save prompt, the close()
        # call above will automatically focus the view which requires
        # the save prompt. The code below makes sure that the correct
        # view gets focused after the save prompt closes.

        if target_view and window.active_view().id() != target_view.id():
            window.focus_view(target_view)

class FocusMostRecentTabCloserListener(sublime_plugin.EventListener):
    def on_activated(self, view):
        """ Stores the time the view is focused in the view's settings. """
        view.settings().set(LAST_FOCUS_TIME_KEY, time.time())
...