Skip to content

Commit

Permalink
Fixing goto file will move the cursor when the file is already opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed Aug 22, 2024
1 parent b08d0f0 commit 658f401
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
12 changes: 7 additions & 5 deletions Common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function Self.path_exists(path)
end


function Self.HandleOpenFile(path, bp, lineNum)
function Self.HandleOpenFile(path, bp, lineNum, gotoLineIfExists)
if Self.OmniNewFileMethod == "smart_newtab" then
Self.SmartNewTab(path, bp, lineNum)
Self.SmartNewTab(path, bp, lineNum, gotoLineIfExists)
return
end

Expand All @@ -87,7 +87,7 @@ function Self.HandleOpenFile(path, bp, lineNum)
end

-- NOTE: lineNum is string
function Self.SmartNewTab(path, bp, lineNum)
function Self.SmartNewTab(path, bp, lineNum, gotoLineIfExists)
local cleanFilepath = filepath.Clean(path)

-- If current pane is empty, we can open in it
Expand Down Expand Up @@ -118,8 +118,10 @@ function Self.SmartNewTab(path, bp, lineNum)
-- NOTE: SetActive functions has index starting at 0 instead lol
micro.Tabs():SetActive(i - 1)
micro.Tabs().List[i]:SetActive(j - 1)
currentPane.Cursor:ResetSelection()
currentPane:GotoCmd({lineNum})
if gotoLineIfExists then
currentPane.Cursor:ResetSelection()
currentPane:GotoCmd({lineNum})
end
-- currentPane:Relocate()
return
end
Expand Down
2 changes: 1 addition & 1 deletion History.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function GoToHistoryEntry(bp, entry)
end

-- micro.Log("We have ", #micro.Tabs().List, " tabs")
Common.HandleOpenFile(entryFilePath, bp, "1")
Common.HandleOpenFile(entryFilePath, bp, "1", true)
micro.CurPane().Cursor:ResetSelection()
micro.CurPane().Cursor:GotoLoc(Common.LocBoundCheck(micro.CurPane().Buf, entry.CursorLoc))
micro.CurPane():Relocate()
Expand Down
8 changes: 4 additions & 4 deletions Search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ local OmniSearchText = ""
local Self = {}

-- NOTE: lineNum is string
function fzfParseOutput(output, bp, lineNum)
function fzfParseOutput(output, bp, lineNum, gotoLineIfExists)
micro.Log("fzfParseOutput called")
if output ~= "" then
local file = string.gsub(output, "[\n\r]", "")
if file == nil then
return
end
Common.HandleOpenFile(file, bp, lineNum)
Common.HandleOpenFile(file, bp, lineNum, gotoLineIfExists)
end
end

Expand Down Expand Up @@ -107,7 +107,7 @@ function FindContent(str, searchLoc)
path = OmniContentFindPath.."/"..path
end

fzfParseOutput(path, bp, lineNumber)
fzfParseOutput(path, bp, lineNumber, true)
end
end

Expand Down Expand Up @@ -180,7 +180,7 @@ function Self.OmniGotoFile(bp)
-- local path, lineNumber = output:match("^(.-):%s*(%d+):")

-- micro.InfoBar():Message("Output is ", output, " and extracted lineNumber is ", lineNumber)
fzfParseOutput(output, bp, "1")
fzfParseOutput(output, bp, "1", false)
end
end

Expand Down
7 changes: 7 additions & 0 deletions repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"history"
],
"Versions": [
{
"Version": "0.2.1",
"Url": "https://github.com/Neko-Box-Coder/MicroOmni/releases/download/v0.2.1/release.zip",
"Require": {
"micro": ">=2.0.13"
}
},
{
"Version": "0.2.0",
"Url": "https://github.com/Neko-Box-Coder/MicroOmni/releases/download/v0.2.0/release.zip",
Expand Down

0 comments on commit 658f401

Please sign in to comment.