@@ -2,7 +2,8 @@ use std::cell::{RefCell};
22use std:: mem;
33use eframe:: egui:: scroll_area:: ScrollBarVisibility ;
44use eframe:: egui:: { Id , Key , Label , Sense , TextEdit } ;
5- use egui:: Ui ;
5+ use eframe:: emath:: Align ;
6+ use egui:: { Modifiers , Ui } ;
67use json_flat_parser:: { FlatJsonValue , PointerKey , ValueType } ;
78use json_flat_parser:: serializer:: serialize_to_json_with_option;
89use crate :: { ArrayResponse , SHORTCUT_COPY , SHORTCUT_DELETE } ;
@@ -20,6 +21,9 @@ pub struct ObjectTable {
2021 pub editing_index : RefCell < Option < usize > > ,
2122 pub editing_value : RefCell < String > ,
2223 pub focused_cell : Option < CellLocation > ,
24+
25+ pub scroll_to_row_number : usize ,
26+ pub changed_arrow_vertical_scroll : bool ,
2327}
2428
2529impl ObjectTable {
@@ -40,6 +44,8 @@ impl ObjectTable {
4044 editing_index : RefCell :: new ( None ) ,
4145 editing_value : RefCell :: new ( "" . to_string ( ) ) ,
4246 focused_cell : None ,
47+ scroll_to_row_number : 0 ,
48+ changed_arrow_vertical_scroll : false ,
4349 }
4450 }
4551
@@ -61,6 +67,10 @@ impl ObjectTable {
6167 . max_scroll_height ( parent_height)
6268 . scroll_bar_visibility ( ScrollBarVisibility :: AlwaysVisible )
6369 ;
70+ if self . changed_arrow_vertical_scroll {
71+ self . changed_arrow_vertical_scroll = false ;
72+ table = table. scroll_to_row ( self . scroll_to_row_number , Some ( Align :: Center ) ) ;
73+ }
6474 table = table. column ( Column :: auto ( ) . clip ( true ) . resizable ( true ) ) ;
6575 table = table. column ( Column :: remainder ( ) . clip ( true ) . resizable ( true ) ) ;
6676 table
@@ -95,6 +105,9 @@ impl ObjectTable {
95105 * self . editing_value . borrow_mut ( ) = entry. value . clone ( ) . unwrap_or_default ( ) ;
96106 * editing_index = Some ( row_index) ;
97107 }
108+ if response. clicked ( ) {
109+ self . focused_cell = Some ( CellLocation { column_index : 1 , row_index : table_row_index, is_pinned_column_table : false } ) ;
110+ }
98111 response. context_menu ( |ui| {
99112 self . focused_cell = Some ( CellLocation { column_index : 1 , row_index : table_row_index, is_pinned_column_table : false } ) ;
100113 let button = ButtonWithIcon :: new ( "Edit" , PENCIL ) ;
@@ -115,11 +128,6 @@ impl ObjectTable {
115128 }
116129 } ) ;
117130
118- if let Some ( cell_location) = self . focused_cell {
119- if cell_location. row_index == table_row_index && !response. context_menu_opened ( ) {
120- self . focused_cell = None ;
121- }
122- }
123131 Some ( response)
124132 }
125133 } ) ;
@@ -188,6 +196,57 @@ impl ObjectTable {
188196 let mut copied_value = None ;
189197 let has_hovered_cell = array_response. hover_data . hovered_cell . is_some ( ) ;
190198 ui. input_mut ( |i| {
199+ if i. key_pressed ( Key :: Escape ) {
200+ self . focused_cell = None ;
201+ }
202+ if let Some ( focused_cell) = self . focused_cell . as_mut ( ) {
203+ // Tab is not consumed, so it also navigate to next component... will try after upgrading egui
204+ // if i.consume_key(Modifiers::NONE, Key::Tab) {
205+ // if !focused_cell.is_pinned_column_table
206+ // && focused_cell.column_index < self.column_selected.len() - 1
207+ // {
208+ // focused_cell.column_index = focused_cell.column_index + 1;
209+ // self.scroll_to_column_number = focused_cell.column_index;
210+ // self.changed_arrow_horizontal_scroll = true;
211+ // } else if !focused_cell.is_pinned_column_table
212+ // && focused_cell.row_index < self.nodes.len() - 1
213+ // {
214+ // focused_cell.column_index = 0;
215+ // focused_cell.row_index = focused_cell.row_index + 1;
216+ // self.scroll_to_row_number = focused_cell.row_index;
217+ // self.changed_arrow_vertical_scroll = true;
218+ // } else if focused_cell.is_pinned_column_table
219+ // && focused_cell.column_index < self.column_pinned.len() - 1
220+ // {
221+ // focused_cell.column_index = focused_cell.column_index + 1;
222+ // } else if focused_cell.is_pinned_column_table {
223+ // focused_cell.column_index = 1;
224+ // focused_cell.row_index = focused_cell.row_index + 1;
225+ // self.scroll_to_row_number = focused_cell.row_index;
226+ // self.changed_arrow_vertical_scroll = true;
227+ // }
228+ // }
229+ if i. consume_key ( Modifiers :: NONE , Key :: ArrowLeft ) {
230+ // do nothing but consume the event
231+ }
232+ if i. consume_key ( Modifiers :: NONE , Key :: ArrowRight ) {
233+ // do nothing but consume the event
234+ }
235+ if i. consume_key ( Modifiers :: NONE , Key :: ArrowUp ) {
236+ if focused_cell. row_index > 0 {
237+ focused_cell. row_index = focused_cell. row_index - 1 ;
238+ self . scroll_to_row_number = focused_cell. row_index ;
239+ self . changed_arrow_vertical_scroll = true ;
240+ }
241+ }
242+ if i. consume_key ( Modifiers :: NONE , Key :: ArrowDown ) {
243+ if focused_cell. row_index < self . filtered_nodes . len ( ) - 1 {
244+ focused_cell. row_index = focused_cell. row_index + 1 ;
245+ self . scroll_to_row_number = focused_cell. row_index ;
246+ self . changed_arrow_vertical_scroll = true ;
247+ }
248+ }
249+ }
191250 if i. consume_shortcut ( & SHORTCUT_DELETE ) {
192251 i. events . push ( egui:: Event :: Key {
193252 key : Key :: Delete ,
0 commit comments