Skip to content

Commit 3305c41

Browse files
Merge pull request #8 from Neko-Box-Coder/TabSearch
Adding TabSearch and SpawnNewCursor
2 parents 87874c2 + 4211366 commit 3305c41

File tree

8 files changed

+203
-100
lines changed

8 files changed

+203
-100
lines changed

Common.lua

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ local buffer = import("micro/buffer")
44
local util = import("micro/util")
55

66
local os = import("os")
7+
local ioutil = import("io/ioutil")
78
local filepath = import("path/filepath")
89

910
local Self = {}
1011

1112
Self.OmniContentArgs = config.GetGlobalOption("OmniGlobalSearchArgs")
1213
Self.OmniLocalSearchArgs = config.GetGlobalOption("OmniLocalSearchArgs")
1314
Self.OmniGotoFileArgs = config.GetGlobalOption("OmniGotoFileArgs")
15+
Self.OmniTabSearchArgs = config.GetGlobalOption("OmniTabSearchArgs")
16+
1417
Self.OmniSelectType = config.GetGlobalOption("OmniSelectType")
1518
Self.OmniHistoryLineDiff = config.GetGlobalOption("OmniHistoryLineDiff")
1619
Self.OmniHistoryTimeTravelMulti = config.GetGlobalOption("OmniHistoryTimeTravelMulti")
17-
Self.OmniCanUseNewCursor = config.GetGlobalOption("OmniCanUseNewCursor")
20+
Self.OmniCanUseAddCursor = config.GetGlobalOption("OmniCanUseAddCursor")
1821

1922
-- TODO: Allow setting highlight to use regex or not
2023

@@ -111,7 +114,7 @@ function Self.OpenPaneIfExist(path)
111114
-- micro.Log("currentBuf.Path:", currentBuf.Path)
112115
-- end
113116

114-
if currentBuf ~= nil and currentBuf.AbsPath ~= "" and currentBuf.AbsPath ~= nil then
117+
if currentBuf ~= nil and currentBuf.AbsPath ~= nil and currentBuf.AbsPath ~= "" then
115118
local calculatedAbsPath = filepath.Abs(cleanFilepath)
116119
if not filepath.IsAbs(cleanFilepath) and wdErr == nil then
117120
local absPath, absErr = filepath.Abs(filepath.Join(wd, cleanFilepath))
@@ -195,4 +198,26 @@ function Self.LocBoundCheck(buf, loc)
195198
return returnLoc
196199
end
197200

201+
function Self.CreateRuntimeFile(relativePath, data)
202+
local microOmniDir = config.ConfigDir.."/plug/MicroOmni/"
203+
if not Self.path_exists(filepath.Dir(microOmniDir..relativePath)) then
204+
local err = os.MkdirAll(filepath.Dir(microOmniDir..relativePath), os.ModePerm)
205+
if err ~= nil then
206+
micro.InfoBar():Error( "Failed to create dir: ", filepath.Dir(microOmniDir..relativePath),
207+
" with error ", err)
208+
return "", false
209+
end
210+
end
211+
212+
local err = ioutil.WriteFile( microOmniDir..relativePath,
213+
data,
214+
os.ModePerm)
215+
if err ~= nil then
216+
micro.InfoBar():Error( "Failed to write to file: ", microOmniDir..relativePath,
217+
" with error ", err)
218+
return "", false
219+
end
220+
return microOmniDir..relativePath, true
221+
end
222+
198223
return Self

Diff.lua

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ local micro = import("micro")
22

33
local shell = import("micro/shell")
44
local buffer = import("micro/buffer")
5-
65
local filepath = import("path/filepath")
7-
local os = import("os")
8-
local ioutil = import("io/ioutil")
9-
106
local config = import("micro/config")
117
local fmt = import('fmt')
128
package.path = fmt.Sprintf('%s;%s/plug/MicroOmni/?.lua', package.path, config.ConfigDir)
@@ -19,29 +15,6 @@ local OmniDiffPlusFile = true
1915
local OmniDiffTargetPanes = {}
2016
local OmniDiffDiffPanes = {}
2117

22-
23-
local function createRuntimeFile(relativePath, data)
24-
local microOmniDir = config.ConfigDir.."/plug/MicroOmni/"
25-
if not Common.path_exists(filepath.Dir(microOmniDir..relativePath)) then
26-
local err = os.MkdirAll(filepath.Dir(microOmniDir..relativePath), os.ModePerm)
27-
if err ~= nil then
28-
micro.InfoBar():Error( "Failed to create dir: ", filepath.Dir(microOmniDir..relativePath),
29-
" with error ", err)
30-
return "", false
31-
end
32-
end
33-
34-
local err = ioutil.WriteFile( microOmniDir..relativePath,
35-
data,
36-
os.ModePerm)
37-
if err ~= nil then
38-
micro.InfoBar():Error( "Failed to write to file: ", microOmniDir..relativePath,
39-
" with error ", err)
40-
return "", false
41-
end
42-
return microOmniDir..relativePath, true
43-
end
44-
4518
local function processDiffOutput(output)
4619
local outputLines = {}
4720
local currentLineIndex = 1
@@ -214,8 +187,8 @@ local function OnDiffFinishCallback(resp, cancelled)
214187
-- Create temp files if needed
215188
if tabSpecified and micro.Tabs().List[tabIndex].Panes[splitIndex].Buf:Modified() then
216189
local createdPath, success =
217-
createRuntimeFile( "./temp/minus.temp",
218-
micro.Tabs().List[tabIndex].Panes[splitIndex].Buf:Bytes())
190+
Common.CreateRuntimeFile( "./temp/minus.temp",
191+
micro.Tabs().List[tabIndex].Panes[splitIndex].Buf:Bytes())
219192
if not success then
220193
return
221194
end
@@ -224,7 +197,7 @@ local function OnDiffFinishCallback(resp, cancelled)
224197

225198
if micro.CurPane().Buf:Modified() then
226199
local createdPath, success =
227-
createRuntimeFile("./temp/plus.temp", micro.CurPane().Buf:Bytes())
200+
Common.CreateRuntimeFile("./temp/plus.temp", micro.CurPane().Buf:Bytes())
228201
if not success then
229202
return
230203
end
@@ -238,7 +211,7 @@ local function OnDiffFinishCallback(resp, cancelled)
238211
if micro.CurPane().Buf:Modified() then
239212
micro.Log("A")
240213
local createdPath, success =
241-
createRuntimeFile("./temp/minus.temp", micro.CurPane().Buf:Bytes())
214+
Common.CreateRuntimeFile("./temp/minus.temp", micro.CurPane().Buf:Bytes())
242215
if not success then
243216
return
244217
end
@@ -247,8 +220,8 @@ local function OnDiffFinishCallback(resp, cancelled)
247220

248221
if tabSpecified and micro.Tabs().List[tabIndex].Panes[splitIndex].Buf:Modified() then
249222
local createdPath, success =
250-
createRuntimeFile( "./temp/plus.temp",
251-
micro.Tabs().List[tabIndex].Panes[splitIndex].Buf:Bytes())
223+
Common.CreateRuntimeFile( "./temp/plus.temp",
224+
micro.Tabs().List[tabIndex].Panes[splitIndex].Buf:Bytes())
252225
if not success then
253226
return
254227
end

Highlight.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ local function PerformMultiCursor(bp, forceMove)
105105
local lastCursor = bp.Buf:GetCursor(bp.Buf:NumCursors() - 1)
106106
local moveCursor = false
107107

108-
if Common.OmniCanUseNewCursor then
108+
if Common.OmniCanUseAddCursor then
109109
moveCursor = not lastCursor:HasSelection()
110110
else
111111
moveCursor = ((bp.Buf:NumCursors() == 1 and not OmniFirstMultiCursorSpawned) and {true} or {false})[1]
@@ -120,12 +120,13 @@ local function PerformMultiCursor(bp, forceMove)
120120
bp:Deselect()
121121
local currentLoc = lastCursor.Loc
122122
-- searchStart = bp.Buf, buffer.Loc(currentLoc.X, currentLoc.Y)
123-
searchStart = Common.LocBoundCheck(bp.Buf, buffer.Loc(currentLoc.X, currentLoc.Y - 1))
123+
-- searchStart = Common.LocBoundCheck(bp.Buf, buffer.Loc(currentLoc.X, currentLoc.Y - 1))
124+
searchStart = Common.LocBoundCheck(bp.Buf, buffer.Loc(0, currentLoc.Y))
124125
-- bp.Cursor:Deselect(false)
125126
else
126127
OmniFirstMultiCursorSpawned = false
127128

128-
if Common.OmniCanUseNewCursor then
129+
if Common.OmniCanUseAddCursor then
129130
searchStart = buffer.Loc(lastCursor.CurSelection[2].X, lastCursor.CurSelection[2].Y)
130131
else
131132
searchStart = buffer.Loc(lastCursor.Loc.X, lastCursor.Loc.Y)
@@ -146,7 +147,7 @@ local function PerformMultiCursor(bp, forceMove)
146147

147148
-- Spawn new cursor if we don't move the last cursor
148149
if not moveCursor then
149-
if Common.OmniCanUseNewCursor then
150+
if Common.OmniCanUseAddCursor then
150151
lastCursor = buffer.NewCursor(bp.Buf, buffer.Loc(0, 0))
151152
else
152153
if not bp:SpawnMultiCursorDown() then
@@ -159,7 +160,7 @@ local function PerformMultiCursor(bp, forceMove)
159160
end
160161
end
161162

162-
if Common.OmniCanUseNewCursor then
163+
if Common.OmniCanUseAddCursor then
163164
lastCursor:SetSelectionStart(foundLocs[1])
164165
lastCursor:SetSelectionEnd(foundLocs[2])
165166
lastCursor.OrigSelection[1].X = lastCursor.CurSelection[1].X

MicroOmni.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "0.2.3"
1+
VERSION = "0.3.0"
22

33
-- luacheck . --globals import VERSION preQuit onAnyEvent init --ignore 212 542 611 612 613 614
44

@@ -229,8 +229,9 @@ local function InitializeSettings()
229229
end
230230
end
231231

232-
233-
Common.OmniCanUseNewCursor = false
232+
if Common.OmniCanUseAddCursor == nil then
233+
Common.OmniCanUseAddCursor = false
234+
end
234235

235236
if Common.OmniMinimapScrollContent == nil then
236237
Common.OmniMinimapScrollContent = true
@@ -325,6 +326,19 @@ local function InitializeSettings()
325326
"--preview-window 'down,+{1}-/2' "..
326327
"--preview 'bat -f -n --highlight-line {1} {filePath}'"
327328
end
329+
330+
if Common.OmniTabSearchArgs == nil or Common.OmniTabSearchArgs == "" then
331+
Common.OmniTabSearchArgs =
332+
"--header='enter: select | alt-enter: output filtered results | alt-q/esc: exit | "..
333+
"page-[up/down]: preview-[up/down] | alt-[up/down]: half-page-[up/down]' "..
334+
"--bind 'start:reload:bat {filePath}' "..
335+
"--delimiter : -i --reverse "..
336+
"--bind page-up:preview-half-page-up,page-down:preview-half-page-down,"..
337+
"alt-up:half-page-up,alt-down:half-page-down,alt-q:abort "..
338+
"--bind 'alt-enter:change-multi+select-all+accept' "..
339+
"--preview-window 'down,+{2}-/2' "..
340+
"--preview 'bat -f -n --highlight-line {2} {1}'"
341+
end
328342

329343
if Common.OmniFzfCmd == nil then
330344
Common.OmniFzfCmd = "fzf"
@@ -381,6 +395,10 @@ function init()
381395
config.MakeCommand("OmniTabScrollRight", OmniTabScrollRight, config.NoComplete)
382396
config.MakeCommand("OmniTabScrollLeft", OmniTabScrollLeft, config.NoComplete)
383397

398+
config.MakeCommand("OmniTabSearch", Search.OmniTabSearch, config.NoComplete)
399+
400+
401+
384402
config.MakeCommand("OmniTest", OmniTest, TestCompleter)
385403
config.MakeCommand("OmniTest2", OmniTest2, config.NoComplete)
386404
config.MakeCommand("OmniTest3", OmniTest3, config.NoComplete)

0 commit comments

Comments
 (0)