From c6a3bc89f6a87ac41c09c62a07c75079b8840afd Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Thu, 14 Sep 2023 20:04:56 +0200 Subject: [PATCH 1/4] Allow filemanager to open in tabs This adds a configuration option to allow filemanager to open a selected file in a new tab instead of a new split. --- filemanager-plugin/filemanager.lua | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/filemanager-plugin/filemanager.lua b/filemanager-plugin/filemanager.lua index fef17d4..754a461 100644 --- a/filemanager-plugin/filemanager.lua +++ b/filemanager-plugin/filemanager.lua @@ -1,4 +1,4 @@ -VERSION = "3.5.1" +VERSION = "3.5.2" local micro = import("micro") local config = import("micro/config") @@ -21,6 +21,8 @@ local current_dir = os.Getwd() local highest_visible_indent = 0 -- Holds a table of paths -- objects from new_listobj() calls local scanlist = {} +-- Holds the selected cursor y pos inbetween closes and opens +local s_cursy = 2 -- Get a new object used when adding to scanlist local function new_listobj(p, d, o, i) @@ -525,8 +527,17 @@ local function try_open_at_y(y) else -- If it's a file, then open it micro.InfoBar():Message("Filemanager opened ", scanlist[y].abspath) - -- Opens the absolute path in new vertical view + -- Opens the absolute path in new tab or a new split + if config.GetGlobalOption("filemanager.openontab") then + -- CurView():VSplitIndex(NewBufferFromFile(scanlist[y].abspath), 1) + local nfile = scanlist[y].abspath + local rpath = shell.RunCommand('realpath \'' .. nfile .. '\' --relative-to=\'' .. os.Getwd() .. '\'') + toggle_tree() + micro.CurPane():NewTabCmd({string.sub(rpath, 1, -2)}) + toggle_tree() + else micro.CurPane():VSplitIndex(buffer.NewBufferFromFile(scanlist[y].abspath), true) + end -- Resizes all views after opening a file -- tabs[curTab + 1]:Resize() end @@ -849,12 +860,19 @@ local function open_tree() tree_view.Buf:SetOptionNative("scrollbar", false) -- Fill the scanlist, and then print its contents to tree_view + if 0 == #scanlist then update_current_dir(os.Getwd()) + else + refresh_view() + end + tree_view.Cursor.Loc.Y = s_cursy + select_line(s_cursy) end -- close_tree will close the tree plugin view and release memory. local function close_tree() if tree_view ~= nil then + s_cursy = tree_view.Cursor.Loc.Y tree_view:Quit() tree_view = nil clear_messenger() @@ -1155,6 +1173,12 @@ function preInsertTab(view) end function preInsertNewline(view) if view == tree_view then + if config.GetGlobalOption("filemanager.openontab") then + -- Simulate the pressing Tab so it opens with Enter key + tab_pressed = true + try_open_at_y(tree_view.Cursor.Loc.Y) + tab_pressed = false + end return false end return true @@ -1352,6 +1376,9 @@ function init() -- Lets the user have the filetree auto-open any time Micro is opened -- false by default, as it's a rather noticable user-facing change config.RegisterCommonOption("filemanager", "openonstart", false) + -- Lets the user open file in new tab or in a new vsplit + -- false by default, as it's a rather noticable user-facing change + config.RegisterCommonOption("filemanager", "openontab", false) -- Open/close the tree view config.MakeCommand("tree", toggle_tree, config.NoComplete) From 99cf8498742c4d78356ca424e68fdd72ec0b3e98 Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Thu, 14 Sep 2023 20:10:04 +0200 Subject: [PATCH 2/4] Update README.md Update documentation for new features --- filemanager-plugin/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/filemanager-plugin/README.md b/filemanager-plugin/README.md index 79d983d..24aa251 100644 --- a/filemanager-plugin/README.md +++ b/filemanager-plugin/README.md @@ -25,6 +25,7 @@ If the directory is expanded, there will be a `+` to the left of it. If it is co | `filemanager-compressparent` | Collapse the parent dir when left is pressed on a child file | `true` | | `filemanager-foldersfirst` | Sorts folders above any files | `true` | | `filemanager-openonstart` | Automatically open the file tree when starting Micro | `false` | +| `filemanager-openontab` | Open the selected file in a new tab instead of a split | `false` | ### Commands and Keybindings @@ -36,6 +37,7 @@ If you want to [keybind](https://github.com/zyedidia/micro/blob/master/runtime/h | :------- | :------------------------- | :------------------------------------------------------------------------------------------ | :------------------------------------ | | `tree` | - | Open/close the tree | `filemanager.toggle_tree` | | - | Tab & MouseLeft | Open a file, or go into the directory. Goes back a dir if on `..` | `filemanager.try_open_at_cursor` | +| - | Enter | If `openontab` is true, open selected file in new tab | `filemanager.try_open_at_cursor` | | - | | Expand directory in tree listing | `filemanager.uncompress_at_cursor` | | - | | Collapse directory listing | `filemanager.compress_at_cursor` | | - | Shift ⬆ | Go to the target's parent directory | `filemanager.goto_parent_dir` | From bc39a2ae88c1ce402c2cc25d575b48ca731f6c65 Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Thu, 14 Sep 2023 20:11:05 +0200 Subject: [PATCH 3/4] Update repo.json Update version --- filemanager-plugin/repo.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/filemanager-plugin/repo.json b/filemanager-plugin/repo.json index 4bd7de2..2757003 100644 --- a/filemanager-plugin/repo.json +++ b/filemanager-plugin/repo.json @@ -39,6 +39,13 @@ "Require": { "micro": ">=2.0.0-1" } + }, + { + "Version": "3.5.2", + "Url": "https://github.com/micro-editor/updated-plugins/releases/download/v1.0.0/filemanager-3.5.2.zip", + "Require": { + "micro": ">=2.0.0-1" + } } ] } From dd8208514ff60fba0d528255470edfeb30dd0b5f Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Sat, 15 Feb 2025 12:31:53 -0500 Subject: [PATCH 4/4] Move README to help file and import it into the help system this commit is based on the OpenInTab PR from github.com/X-Ryl669 --- filemanager-plugin/CHANGELOG.md | 8 ++++++++ filemanager-plugin/filemanager.lua | 7 +++++-- filemanager-plugin/{README.md => help/filemanager.md} | 0 filemanager-plugin/repo.json | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) rename filemanager-plugin/{README.md => help/filemanager.md} (100%) diff --git a/filemanager-plugin/CHANGELOG.md b/filemanager-plugin/CHANGELOG.md index 46d51c4..338fbd6 100644 --- a/filemanager-plugin/CHANGELOG.md +++ b/filemanager-plugin/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +## [3.5.2.1] - 2025-02-15 + +- Move README to help file and import it into the help system + +## [3.5.2] - 2023-09-14 + +- Allow filemanager to open files in new tab, either using Tab or Enter + ## [3.4.0] - 2018-10-22 ### Fixed diff --git a/filemanager-plugin/filemanager.lua b/filemanager-plugin/filemanager.lua index 754a461..e685b6a 100644 --- a/filemanager-plugin/filemanager.lua +++ b/filemanager-plugin/filemanager.lua @@ -1,4 +1,4 @@ -VERSION = "3.5.2" +VERSION = "3.5.2.1" local micro = import("micro") local config = import("micro/config") @@ -528,7 +528,7 @@ local function try_open_at_y(y) -- If it's a file, then open it micro.InfoBar():Message("Filemanager opened ", scanlist[y].abspath) -- Opens the absolute path in new tab or a new split - if config.GetGlobalOption("filemanager.openontab") then + if config.GetGlobalOption("filemanager.openontab") then -- CurView():VSplitIndex(NewBufferFromFile(scanlist[y].abspath), 1) local nfile = scanlist[y].abspath local rpath = shell.RunCommand('realpath \'' .. nfile .. '\' --relative-to=\'' .. os.Getwd() .. '\'') @@ -1394,6 +1394,9 @@ function init() -- TODO: Change it to work with git, based on untracked/changed/added/whatever config.AddRuntimeFile("filemanager", config.RTSyntax, "syntax.yaml") + -- Add the help file + config.AddRuntimeFile("filemanager", config.RTHelp, "help/filemanager.md") + -- NOTE: This must be below the syntax load command or coloring won't work -- Just auto-open if the option is enabled -- This will run when the plugin first loads diff --git a/filemanager-plugin/README.md b/filemanager-plugin/help/filemanager.md similarity index 100% rename from filemanager-plugin/README.md rename to filemanager-plugin/help/filemanager.md diff --git a/filemanager-plugin/repo.json b/filemanager-plugin/repo.json index 2757003..49ae220 100644 --- a/filemanager-plugin/repo.json +++ b/filemanager-plugin/repo.json @@ -46,6 +46,13 @@ "Require": { "micro": ">=2.0.0-1" } + }, + { + "Version": "3.5.2.1", + "Url": "https://github.com/micro-editor/updated-plugins/releases/download/v1.0.0/filemanager-3.5.2.1.zip", + "Require": { + "micro": ">=2.0.0-1" + } } ] }