editor/nwm bug fixes

This commit is contained in:
kepler155c@gmail.com
2020-05-08 22:31:06 -06:00
parent 1fc2d08c18
commit ad4cc5884f
2 changed files with 19 additions and 20 deletions

View File

@@ -9,7 +9,7 @@ local fs = _G.fs
local multishell = _ENV.multishell local multishell = _ENV.multishell
local os = _G.os local os = _G.os
local shell = _ENV.shell local shell = _ENV.shell
local term = _G.term local term = _G.term.current()
local textutils = _G.textutils local textutils = _G.textutils
local _format = string.format local _format = string.format
@@ -318,7 +318,7 @@ local page = UI.Page {
show = function(self) show = function(self)
local t = { } local t = { }
for _,v in pairs(config.recent or { }) do for _,v in pairs(config.recent or { }) do
table.insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v }) _insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v })
end end
self.grid:setValues(t) self.grid:setValues(t)
self.grid:setIndex(1) self.grid:setIndex(1)
@@ -453,10 +453,9 @@ local page = UI.Page {
event = 'slide_hide', event = 'slide_hide',
}, },
show = function(self, values) show = function(self, values)
local m = 12 local m = Util.reduce(values, function(m, v)
for _, v in pairs(values) do return #v.text > m and #v.text or m
m = #v.text > m and #v.text or m end, 12)
end
m = m + 3 m = m + 3
m = m > self.parent.width and self.parent.width or m m = m > self.parent.width and self.parent.width or m
self.ox = -m self.ox = -m
@@ -492,7 +491,9 @@ local page = UI.Page {
scan = function(self) scan = function(self)
self.values = { } self.values = { }
for k, v in pairs(device) do for k, v in pairs(device) do
table.insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' }) if type(v.side) == 'string' then
_insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' })
end
end end
end, end,
postInit = function(self) postInit = function(self)
@@ -519,7 +520,7 @@ local page = UI.Page {
for k, v in pairs(dev) do for k, v in pairs(dev) do
if type(v) == 'function' then if type(v) == 'function' then
local m = docs and docs[k] and docs[k]:match('^function%((.+)%).+') local m = docs and docs[k] and docs[k]:match('^function%((.+)%).+')
table.insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' }) _insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' })
end end
end end
end) end)
@@ -648,9 +649,9 @@ local function getFileInfo(path)
config.recent = config.recent or { } config.recent = config.recent or { }
Array.removeByValue(config.recent, path) Array.removeByValue(config.recent, path)
table.insert(config.recent, 1, path) _insert(config.recent, 1, path)
while #config.recent > 10 do while #config.recent > 10 do
table.remove(config.recent) _remove(config.recent)
end end
Config.update('editor', config) Config.update('editor', config)
@@ -763,7 +764,7 @@ actions = {
local last = _remove(undo.chain) local last = _remove(undo.chain)
if last then if last then
undo.active = true undo.active = true
table.insert(undo.redo, { }) _insert(undo.redo, { })
for i = #last, 1, -1 do for i = #last, 1, -1 do
local u = last[i] local u = last[i]
actions[u.action](_unpack(u.args)) actions[u.action](_unpack(u.args))
@@ -777,14 +778,14 @@ actions = {
undo_add = function(entry) undo_add = function(entry)
if undo.active then if undo.active then
local last = undo.redo[#undo.redo] local last = undo.redo[#undo.redo]
table.insert(last, entry) _insert(last, entry)
else else
if not undo.redo_active then if not undo.redo_active then
undo.redo = { } undo.redo = { }
end end
local last = undo.chain[#undo.chain] local last = undo.chain[#undo.chain]
if last and undo.continue then if last and undo.continue then
table.insert(last, entry) _insert(last, entry)
else else
_insert(undo.chain, { entry }) _insert(undo.chain, { entry })
end end

View File

@@ -76,7 +76,7 @@ local function hook(e, eventData)
if clickedTab then if clickedTab then
if clickedTab ~= currentTab then if clickedTab ~= currentTab then
clickedTab.window.raise() clickedTab.window.raise()
multishell.setFocus(clickedTab.uid) kernel.raise(clickedTab.uid)
end end
kernel.event(events[e], { kernel.event(events[e], {
@@ -88,8 +88,6 @@ local function hook(e, eventData)
end end
local function run(args) local function run(args)
local window = Glasses.create(args)
local titleBar = Glasses.create({ local titleBar = Glasses.create({
x = args.x, x = args.x,
y = args.y - 1, y = args.y - 1,
@@ -102,17 +100,17 @@ local function run(args)
titleBar.canvas:write(args.width - 2, 1, ' x ', nil, 'black') titleBar.canvas:write(args.width - 2, 1, ' x ', nil, 'black')
titleBar.redraw() titleBar.redraw()
multishell.openTab({ kernel.run({
path = args.path, path = args.path,
args = args.args, args = args.args,
hidden = true, hidden = true,
onDestroy = function() onExit = function(self)
Util.removeByValue(config.session, args) Util.removeByValue(config.session, args)
Config.update('nwm', config) Config.update('nwm', config)
window.destroy() self.window.destroy()
titleBar.destroy() titleBar.destroy()
end, end,
window = window, window = Glasses.create(args),
titleBar = titleBar, titleBar = titleBar,
wmargs = args, wmargs = args,
}) })