vim mode also working now
This commit is contained in:
29
init.lua
29
init.lua
@@ -24,8 +24,17 @@ local _send_notification = ya.sync(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
local _get_real_index = ya.sync(function(state, idx)
|
||||||
|
for key, value in pairs(state.indexes) do
|
||||||
|
if value == idx then
|
||||||
|
return key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end)
|
||||||
|
|
||||||
local _load_state = ya.sync(function(state)
|
local _load_state = ya.sync(function(state)
|
||||||
ya.err("Persist State")
|
|
||||||
ps.sub_remote("bookmarks", function(body)
|
ps.sub_remote("bookmarks", function(body)
|
||||||
if not state.bookmarks and body then
|
if not state.bookmarks and body then
|
||||||
state.indexes = {}
|
state.indexes = {}
|
||||||
@@ -41,7 +50,6 @@ local _load_state = ya.sync(function(state)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local _save_state = ya.sync(function(state, bookmarks, indexes)
|
local _save_state = ya.sync(function(state, bookmarks, indexes)
|
||||||
ya.err("Save State")
|
|
||||||
if not bookmarks then
|
if not bookmarks then
|
||||||
ps.pub_static(10, "bookmarks", nil)
|
ps.pub_static(10, "bookmarks", nil)
|
||||||
return
|
return
|
||||||
@@ -56,15 +64,15 @@ local _save_state = ya.sync(function(state, bookmarks, indexes)
|
|||||||
for key, value in pairs(bookmarks) do
|
for key, value in pairs(bookmarks) do
|
||||||
-- Only save bookmarks in upper case keys
|
-- Only save bookmarks in upper case keys
|
||||||
if string.match(value.on, "%u") then
|
if string.match(value.on, "%u") then
|
||||||
table.insert(save_bookmarks, value)
|
save_bookmarks[key] = value
|
||||||
table.insert(save_indexes, indexes[key])
|
local real_index = _get_real_index(key)
|
||||||
|
save_indexes[real_index] = indexes[real_index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
save_state = { bookmarks = save_bookmarks, indexes = save_indexes }
|
save_state = { bookmarks = save_bookmarks, indexes = save_indexes }
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.err("SAVE STATE: " .. serialize(save_state))
|
|
||||||
ps.pub_static(10, "bookmarks", save_state)
|
ps.pub_static(10, "bookmarks", save_state)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -106,9 +114,6 @@ local save_bookmark = ya.sync(function(state, idx)
|
|||||||
cursor = folder.cursor,
|
cursor = folder.cursor,
|
||||||
}
|
}
|
||||||
|
|
||||||
ya.err("INDEXES " .. serialize(state.indexes))
|
|
||||||
ya.err("BOOKMARKS " .. serialize(state.bookmarks))
|
|
||||||
|
|
||||||
if state.persist then
|
if state.persist then
|
||||||
_save_state(state.bookmarks, state.indexes)
|
_save_state(state.bookmarks, state.indexes)
|
||||||
end
|
end
|
||||||
@@ -147,11 +152,9 @@ local delete_bookmark = ya.sync(function(state, idx)
|
|||||||
|
|
||||||
state.bookmarks[idx] = nil
|
state.bookmarks[idx] = nil
|
||||||
-- remove the indexes entry for the bookmark
|
-- remove the indexes entry for the bookmark
|
||||||
for key, value in pairs(state.indexes) do
|
local real_index = _get_real_index(idx)
|
||||||
if value == idx then
|
if real_index then
|
||||||
state.indexes[key] = nil
|
state.indexes[real_index] = nil
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if state.persist then
|
if state.persist then
|
||||||
|
|||||||
Reference in New Issue
Block a user