Skip to content

Commit c47f79d

Browse files
committed
progress towards keyboard cursor
1 parent ce18633 commit c47f79d

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

gui/manipulator.lua

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ function Column:on_select(idx, choice)
262262
-- avoiding an infinite loop
263263
local namelist = self.parent_view.parent_view.namelist
264264
if namelist then
265+
self.shared.set_cursor_col_fn(self)
265266
namelist:setSelected(idx)
266267
end
267268
end
@@ -563,7 +564,8 @@ function Spreadsheet:init()
563564
sort_stack={},
564565
sort_order={}, -- list of indices into filtered_unit_ids (or cache.filtered_units)
565566
cache={}, -- cached pointers; reset at end of frame
566-
cur_col=nil,
567+
cursor_col=nil,
568+
set_cursor_col_fn=self:callback('set_cursor_col'),
567569
refresh_units=true,
568570
refresh_headers=true,
569571
}
@@ -716,12 +718,17 @@ function Spreadsheet:init()
716718
cols,
717719
}
718720

721+
-- teach each column about its relative position so we can track cursor movement
722+
for idx, col in ipairs(cols) do
723+
col.idx = idx
724+
end
725+
719726
-- set up initial sort: primary favorites, secondary name
720727
self.shared.sort_stack[1] = {col=self.subviews.name, rev=false}
721728
self.shared.sort_stack[2] = {col=self.subviews.favorites, rev=false}
722729

723-
-- set initial selection
724-
self:set_cur_col(self.subviews.favorites)
730+
-- set initial keyboard cursor position
731+
self:set_cursor_col(self.subviews.favorites)
725732

726733
self.namelist = self.subviews.name.subviews.col_list
727734
self:addviews{
@@ -737,11 +744,11 @@ end
737744

738745
local CURSOR_PEN = dfhack.pen.parse{fg=COLOR_GREY, bg=COLOR_CYAN}
739746

740-
function Spreadsheet:set_cur_col(col)
741-
if self.shared.cur_col then
742-
self.shared.cur_col.subviews.col_list.cursor_pen = COLOR_LIGHTCYAN
747+
function Spreadsheet:set_cursor_col(col)
748+
if self.shared.cursor_col then
749+
self.shared.cursor_col.subviews.col_list.cursor_pen = COLOR_LIGHTCYAN
743750
end
744-
self.shared.cur_col = col
751+
self.shared.cursor_col = col
745752
col.subviews.col_list.cursor_pen = CURSOR_PEN
746753
end
747754

@@ -755,23 +762,23 @@ function Spreadsheet:zoom_to_unit()
755762
end
756763

757764
function Spreadsheet:zoom_to_col_source()
758-
if not self.shared.cur_col or not self.shared.cur_col.zoom_fn then return end
759-
self.shared.cur_col.zoom_fn()
765+
if not self.shared.cursor_col or not self.shared.cursor_col.zoom_fn then return end
766+
self.shared.cursor_col.zoom_fn()
760767
end
761768

762769
function Spreadsheet:sort_by_current_col()
763-
if not self.shared.cur_col then return end
764-
self.shared.cur_col:sort(true)
770+
if not self.shared.cursor_col then return end
771+
self.shared.cursor_col:sort(true)
765772
end
766773

767774
function Spreadsheet:hide_current_col()
768-
if not self.shared.cur_col then return end
769-
self.shared.cur_col:hide_column()
775+
if not self.shared.cursor_col then return end
776+
self.shared.cursor_col:hide_column()
770777
end
771778

772779
function Spreadsheet:hide_current_col_group()
773-
if not self.shared.cur_col then return end
774-
self.shared.cur_col:hide_group()
780+
if not self.shared.cursor_col then return end
781+
self.shared.cursor_col:hide_group()
775782
end
776783

777784
-- utf8-ize and, if needed, quote and escape

0 commit comments

Comments
 (0)