关闭选项卡>转到上一个编辑的选项卡

问题描述 投票:2回答:1

当关闭sublimetext3中的选项卡时,它总是将我带回到左边的一个,而在sublimetext2上,我被带到之前打开的一个(不一定是左边的)。

这种行为在sublimetext2中非常方便,因为它创建了一种易于回溯的历史记录,只需连续关闭标签即可。

在sublimetext3中有设置吗?

Steps to reproduce

  1. 我打开了3个标签,第3个标签处于活动状态:enter image description here
  2. 我现在去编辑第二个:enter image description here
  3. 我已经完成并决定关闭第二个标签:enter image description here

失败:我不会回到以前编辑的那个:第三个

sublimetext3 sublimetext
1个回答
2
投票

没有设置可以做到这一点。但是,因为它可以使用插件完成,并且我喜欢将我的插件编写技巧保持在最佳状态,所以我已经为您编写了它。

它被称为FocusMostRecentTabClos​​er,代码位于此GitHub Gist下方。

要使用它,请将其保存为FocusMostRecentTabCloser.py目录结构中的Packages,并为focus_most_recent_tab_closer命令指定密钥。例如

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

我没有广泛测试它,它需要Sublime Text 3 build 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())
© www.soinside.com 2019 - 2024. All rights reserved.