mirror of
https://github.com/asherao/dcs-scratchpad.git
synced 2025-10-29 16:56:22 +00:00
don't persist changes on every key stroke
Instead only persist when: - changing pages - hiding the Scratchpad - removing focus from the textarea
This commit is contained in:
parent
158c9dc5f9
commit
22dea08045
@ -67,6 +67,10 @@ local function loadScratchpad()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function savePage(path, content, override)
|
local function savePage(path, content, override)
|
||||||
|
if path == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
log("saving page " .. path)
|
log("saving page " .. path)
|
||||||
lfs.mkdir(lfs.writedir() .. [[Scratchpad\]])
|
lfs.mkdir(lfs.writedir() .. [[Scratchpad\]])
|
||||||
local mode = "a"
|
local mode = "a"
|
||||||
@ -88,6 +92,9 @@ local function loadScratchpad()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- make sure current changes are persisted
|
||||||
|
savePage(currentPage, textarea:getText(), true)
|
||||||
|
|
||||||
local lastPage = nil
|
local lastPage = nil
|
||||||
for _, page in pairs(pages) do
|
for _, page in pairs(pages) do
|
||||||
if currentPage == nil or (lastPage ~= nil and lastPage.path == currentPage) then
|
if currentPage == nil or (lastPage ~= nil and lastPage.path == currentPage) then
|
||||||
@ -104,6 +111,13 @@ local function loadScratchpad()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function prevPage()
|
local function prevPage()
|
||||||
|
if pagesCount == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- make sure current changes are persisted
|
||||||
|
savePage(currentPage, textarea:getText(), true)
|
||||||
|
|
||||||
local lastPage = nil
|
local lastPage = nil
|
||||||
for i, page in pairs(pages) do
|
for i, page in pairs(pages) do
|
||||||
if currentPage == nil or (page.path == currentPage and i ~= 1) then
|
if currentPage == nil or (page.path == currentPage and i ~= 1) then
|
||||||
@ -294,9 +308,6 @@ local function loadScratchpad()
|
|||||||
local lineCountAdded = textarea:getLineCount() - lineCountBefore
|
local lineCountAdded = textarea:getLineCount() - lineCountBefore
|
||||||
local line = lineEnd + lineCountAdded - 1
|
local line = lineEnd + lineCountAdded - 1
|
||||||
textarea:setSelectionNew(line, 0, line, 0)
|
textarea:setSelectionNew(line, 0, line, 0)
|
||||||
|
|
||||||
-- persist text changes to disk
|
|
||||||
savePage(currentPage, textarea:getText(), true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setVisible(b)
|
local function setVisible(b)
|
||||||
@ -418,17 +429,13 @@ local function loadScratchpad()
|
|||||||
skin.skinData.states.released[1].text.fontSize = config.fontSize
|
skin.skinData.states.released[1].text.fontSize = config.fontSize
|
||||||
textarea:setSkin(skin)
|
textarea:setSkin(skin)
|
||||||
|
|
||||||
textarea:addChangeCallback(
|
|
||||||
function(self)
|
|
||||||
savePage(currentPage, self:getText(), true)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
textarea:addFocusCallback(
|
textarea:addFocusCallback(
|
||||||
function(self)
|
function(self)
|
||||||
if self:getFocused() then
|
if self:getFocused() then
|
||||||
lockKeyboardInput()
|
lockKeyboardInput()
|
||||||
else
|
else
|
||||||
unlockKeyboardInput(true)
|
unlockKeyboardInput(true)
|
||||||
|
savePage(currentPage, self:getText(), true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@ -437,6 +444,7 @@ local function loadScratchpad()
|
|||||||
if keyName == "escape" then
|
if keyName == "escape" then
|
||||||
self:setFocused(false)
|
self:setFocused(false)
|
||||||
unlockKeyboardInput(true)
|
unlockKeyboardInput(true)
|
||||||
|
savePage(currentPage, self:getText(), true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user