At 1251393183 time_t, koniu wrote: > + if not compare_select(curtags, data.history.current[screen]) and > #selectedlist(screen) > 0 then > + -- create history table > + if not data.history[screen] then > + data.history[screen] = {}
Bad indent. > + -- limit history > + elseif #data.history[screen] == history.limit then > + table.remove(data.history[screen]) > end Be careful that the limit might have been reduced to let's say 20 to 10. So you won't hit it with a ==, you should do a while > history, remove lines I guess. > + -- store previously selected tags in the history table > + table.insert(data.history[screen], 1, data.history.current[screen]) > + data.history[screen].previous = data.history[screen][1] > + -- store currently selected tags > + data.history.current[screen] = selectedlist(screen) Hum if you want to store tags object I'm ok with that but you should probably use a weak-value table in that case. And be careful if tags are removed from the screen and/or collected by the GC, since your array will be (partially) empty. > --- Revert tag history. > -- @param screen The screen number. > -function history.restore(screen) > +-- @param idx Index in history. Defaults to "previous" which is a special > index > +-- toggling between last two selected sets of tags. Number (eg 1) will go > back > +-- to the given index in history. > +function history.restore(screen, idx) > local s = screen or capi.mouse.screen > local tags = capi.screen[s]:tags() > - for k, t in pairs(tags) do > - t.selected = data.history.past[s][k] > + local i = idx or "previous" > + local previous = selectedlist(s) > + -- do nothing if history empty > + if not data.history[s] or not data.history[s][i] then return end > + -- deselect all tags > + viewnone(s) > + -- select tags from the history entry > + for _, t in ipairs(data.history[s][i]) do > + t.selected = true > end > + -- update currently selected tags table > + data.history.current[s] = data.history[s][i] > + -- store previously selected tags > + data.history[s]["previous"] = previous > + -- remove the reverted history entry > + if i ~= "previous" then table.remove(data.history[s], i) end > end I think that should be split in 2 functions. Add another function like "goback" that goes back N elements in history for example, but leave restore as it is, e.g. only switch between 2 elements. Otherwise, the code actually works. :) Cheers, -- Julien Danjou // ᐰ <jul...@danjou.info> http://julien.danjou.info // 9A0D 5FD9 EB42 22F6 8974 C95C A462 B51E C2FE E5CD // Don't give up.
signature.asc
Description: Digital signature