Code Monkey home page Code Monkey logo

Comments (26)

obgnail avatar obgnail commented on August 13, 2024 1

reopenClosedFiles 多次尝试发现,反复打开,会有一部分失效,一部分成功,比如:第一次我打开 2 个 tab . 第二次打开确实保留了打开的历史记录。关闭后再第三次打开没了。而且很多情况下打开不生效. typora 设置是 打开指定目录.

reopenClosedFiles 的功能是【打开上次退出时尚未关闭的标签页】,因此:

只有在 alt+F4、直接点击右上角【X】按钮等情况,才会生效。如果你是挨个关闭标签,直到关闭最后一个标签导致关闭 Typora,那么就会判定你已经关闭了所有标签,下次打开 Typora 时就不会恢复。

其实这个插件只有 20+ 行代码,我给你加了一下注释,你可以读一下

class reopenClosedFilesPlugin extends BaseCustomPlugin {
    init = () => {
        this.windowTabBarPlugin = null;
        this.saveFile = this.utils.joinPath("./plugin/custom/plugins/reopenClosedFiles/remain.json");
    }

    hotkey = () => [this.config.hotkey]

    process = () => {
        this.utils.addEventListener(this.utils.eventType.allPluginsHadInjected, async () => {
            this.windowTabBarPlugin = this.utils.getPlugin("window_tab");
            if (!this.windowTabBarPlugin) return;
            // 确保文件存在,不存在则创建
            await this.ensureFile();
            if (this.config.auto_reopen_when_init) {
                // 刚打开 Typora 并且当前是空文件(并不是打开特定文件)时,恢复保存的标签
                this.utils.loopDetector(() => File && !this.utils.getFilePath(), this.callback, 20, 200, false);
            }
        })

        // 在关闭 Typora 之前,将现在的所有标签存起来
        this.utils.addEventListener(this.utils.eventType.beforeUnload, () => this.windowTabBarPlugin && this.windowTabBarPlugin.saveTabs(this.saveFile));
    }

    ensureFile = async () => await this.utils.Package.FsExtra.ensureFile(this.saveFile);

    callback = () => this.windowTabBarPlugin && this.windowTabBarPlugin.openSaveTabs(this.saveFile);
}

module.exports = {
    plugin: reopenClosedFilesPlugin,
};

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911

你好,您的需求已经实现。

添加了 reopenClosedFiles 插件,其配置在 custom_plugin.toml 中:

############### reopenClosedFiles ###############
[reopenClosedFiles]
# 右键菜单中展示的名称
name = "打开上次退出时尚未关闭的标签页"
# 是否启用此自定义插件(此插件仅在window_tab启用时生效)
enable = true
# 插件配置
[reopenClosedFiles.config]
# 打开Typora自动打开
# 注意:只当双击typora.exe打开Typora时生效(打开特定文件时,自动打开上次退出时尚未关闭的标签页,明显不符合用户预期)
auto_reopen_when_init = true
# 快捷键
hotkey = ""

麻烦测试一下。有问题请在下面留言。

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911

注:如果你想快速打开之前关闭的文件,可以使用 toolbar 插件:

  1. ctrl + j
  2. 输入【his+空格+你要搜索的文件名】
  3. 上下键选中文件,最后回车即可。

toolbar 插件专为键盘党设计,所有的插件功能皆可通过键盘调用

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

好的!
typora version: 1.7.5
typora_plugin version: 1.5.11
os : Windows 11

测试结果:

  1. toolbar不生效 具体标签 ctrl + j 可以呼出检索框, 后面检索内容没有自动提示,回车也没有检索结果.
    image

  2. reopenClosedFiles 不生效, 将默认配置设置到user.toml 后重启, 打开两个文件tab后关闭typora 然后再打开无效果. 尝试过以管理员身份打开,以及基础尝试等均无效果.

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

reopenClosedFiles 多次尝试发现,反复打开,会有一部分失效,一部分成功, 比如:第一次我打开2个tab . 第二次打开确实保留了打开的历史记录. 关闭后再第三次打开没了. 而且很多情况下打开不生效. typora设置是打开指定目录.

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

ctrl+j 搜索框是多功能搜索,目前支持功能:

  1. tab:切换标签页
  2. plu:使用插件
  3. his:打开最新文件
  4. ops:执行操作
  5. mode:切换模式
  6. theme:临时更换主题

暂时没有 has 这个功能。

使用方法:

例如:

  1. 在搜索框键入 plu sear(注意中间有空格),就能搜索到关键字包含 sear 的插件,
  2. 在搜索框键入 plu (注意包含空格),就会展示所有的插件
  3. 在搜索框键入his docker,就能搜索最近打开文件中,包含docker的文件
  4. 其他 tab、ops、mode 同理

Snipaste_2023-10-14_19-57-38

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

是不是我设置的问题?
his 不生效.
image
image

image

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

20231014201116_rec_

https://github.com/obgnail/typora_plugin/assets/28957658/c77f08c1-8828-4835-af2b-f576b6d63ce0
这个是我的演示录屏.

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911

一个个来,先看看 toolbar 插件。

  1. his 的功能是【重新打开最近关闭的文件】。你先搜索一下 his (含空格),应该会弹出最近关闭的 20 个文件
  2. tab 的功能是:切换标签页(会过滤掉当前的标签)
  3. 麻烦试试 tab、plu、ops、mode、theme 功能有没有问题

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

Snipaste_2023-10-14_20-21-39

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

@pro911

一个个来,先看看 toolbar 插件。

  1. his 的功能是【重新打开最近关闭的文件】。你先搜索一下 his (含空格),应该会弹出最近关闭的 20 个文件
  2. tab 的功能是:切换标签页(会过滤掉当前的标签)
  3. 麻烦试试 tab、plu、ops、mode、theme 功能有没有问题

结果:

  1. 只有his不生效,其他的均可正常使用.
    image

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911

reopenClosedFilesPlugin 的有时候不生效的问题我已经复现,并且解决了。

麻烦测一下 toolbar 有没有问题,问题解决后,我等会发一个 hotfix 版本。

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

键入 his 没有弹出任何内容,是吗?

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

键入 his 没有弹出任何内容,是吗?

是的,我确保了remain.json 里面有记录的情况下去 his doc 并没有提示检索结果

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

reopenClosedFilesPlugin 的有时候不生效的问题,其实只要把

this.utils.loopDetector(() => File && !this.utils.getFilePath(), this.callback, 20, 200, false);

的 200 改成 2000,就解决了(200 是 timeout,200ms 太短了,Typora 来不及完成初始化页面导致的)

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

reopenClosedFilesPlugin 的有时候不生效的问题,其实只要把

this.utils.loopDetector(() => File && !this.utils.getFilePath(), this.callback, 20, 200, false);

的 200 改成 2000,就解决了(200 是 timeout,200ms 太短了,Typora 来不及完成初始化页面导致的)

验证了,确实是.

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911 我知道了,你看一下你发的视频,his 会过滤掉当前的文件,你换一个标签就可以搜到了

class RecentFileTool extends baseToolInterface {
    name = () => "his"
    translate = () => "打开最近文件"

    getRecentFile = async () => {
        if (!File.isNode) return;

        const file = await JSBridge.invoke("setting.getRecentFiles");
        const fileJson = JSON.parse(file || "{}");
        const files = fileJson["files"] || [];
        const folders = fileJson["folders"] || [];
        const result = [];
        for (const file of files) {
            if (file["path"]) {
                result.push({showName: file.path, fixedName: file.path, meta: "file"});
            }
        }
        for (const folder of folders) {
            if (folder["path"]) {
                result.push({showName: folder.path, fixedName: folder.path, meta: "folder"});
            }
        }
        return result
    }

    search = async input => {
        let files = await this.getRecentFile();
        if (!files || files.length === 0) return;

        const current = this.utils.getFilePath();
        files = files.filter(file => file.showName !== current); // 小细节:去掉当前的文件

        return this.baseSearch(input, files, ["fixedName"])
    }

    callback = (fixedName, meta) => {
        if (meta === "file") {
            this.utils.openFile(fixedName);
        } else if (meta === "folder") {
            this.utils.openFolder(fixedName);
        }
    }
}

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

好像还是没有效果.

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

image

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

坏了,那应该是 Typora 1.7 改接口了 😂

我现在在 1.6 版本。麻烦能帮我测试一下吗?

  1. ctrl+j
  2. 键入 mode debug
  3. 选中【调试模式】
  4. 切换到【控制台】标签,看看有没有报错,
  5. 如果没有,在控制台输入
await JSBridge.invoke("setting.getRecentFiles")

看看有没有值输出

Snipaste_2023-10-14_20-57-16

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

重新打开软件,打开debug模式 好像没有报错,而且可以获取到文件和目录. 如图:
image
我在家晚上不知道是vpn繁忙还是网络运营商屏蔽,访问github老断网, 你注意下邮件,我可以给你发邮件.

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911 如果可以的话,麻烦邮件沟通

from typora_plugin.

obgnail avatar obgnail commented on August 13, 2024

@pro911

花了些时间,改善了 toolbar 的查询体验,现在:

  • 支持【交集查询】、【差集查询】,实现高精度查询
  • 添加混合查找功能 all,实现高广度查询

举例:

  • his node learn:查找最近打开的文件,要求文件标题【包含 node 和 learn 两个关键字】
  • plu multi -search:查找插件,要求插件名【包含 multi 关键字,但是不包含 search 关键字】
  • tab -messing:查找所有打开的标签页,要求标签页名称【不包含 messing 关键字】
  • his close -win -mark 标签:查找最近打开的文件,要求文件标题【包含 close、标签,不包含 win、mark】

Snipaste_2023-10-15_23-32-51

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

from typora_plugin.

pro911 avatar pro911 commented on August 13, 2024

好的,已经验证过了,都正常,只是his 检索中文的时候需要结束后再打一个空格才会匹配内容,没有其他的问题.
20231016101135_rec_
https://github.com/obgnail/typora_plugin/assets/28957658/e72af40d-4694-451d-a01b-83aa0899942f

from typora_plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.