@@ -8,16 +8,15 @@ use crate::parser::{replace_occurrences, row_number_entry, search_occurrences};
88use crate :: subtable_window:: SubTable ;
99use crate :: {
1010 concat_string, set_open, ArrayResponse , Window , ACTIVE_COLOR , SHORTCUT_COPY , SHORTCUT_DELETE ,
11- SHORTCUT_REPLACE , SHORTCUT_SAVE_AS ,
11+ SHORTCUT_REPLACE ,
1212} ;
1313use eframe:: egui:: scroll_area:: ScrollBarVisibility ;
1414use eframe:: egui:: style:: Spacing ;
1515use eframe:: egui:: {
1616 Align , Context , CursorIcon , Id , Key , Label , Sense , Style , TextEdit , Ui , Vec2 , Widget ,
1717 WidgetText ,
1818} ;
19- use egui:: Key :: Tab ;
20- use egui:: { EventFilter , Modifiers , TextBuffer } ;
19+ use egui:: { Modifiers , TextBuffer } ;
2120use indexmap:: IndexSet ;
2221use json_flat_parser:: serializer:: serialize_to_json_with_option;
2322use json_flat_parser:: {
@@ -151,6 +150,7 @@ pub struct ArrayTable<'array> {
151150 pub changed_matching_row_selected : bool ,
152151 pub changed_arrow_horizontal_scroll : bool ,
153152 pub changed_arrow_vertical_scroll : bool ,
153+ pub was_editing : bool ,
154154
155155 #[ cfg( not( target_arch = "wasm32" ) ) ]
156156 pub changed_scroll_to_row_value : Option < std:: time:: Instant > ,
@@ -278,7 +278,7 @@ impl<'array> super::View<ArrayResponse> for ArrayTable<'array> {
278278 if self . editing_index . borrow ( ) . is_none ( ) {
279279 self . handle_shortcut ( ui, & mut array_response) ;
280280 }
281-
281+ self . was_editing = false ;
282282 array_response
283283 }
284284}
@@ -432,6 +432,7 @@ impl<'array> ArrayTable<'array> {
432432 cache : Default :: default ( ) ,
433433 opened_windows : Default :: default ( ) ,
434434 search_replace_panel : Default :: default ( ) ,
435+ was_editing : false ,
435436 }
436437 }
437438 pub fn windows ( & mut self , ctx : & Context , array_response : & mut ArrayResponse ) {
@@ -659,14 +660,15 @@ impl<'array> ArrayTable<'array> {
659660 } else {
660661 None
661662 } ;
663+ let focused_cell = self . focused_cell . or ( self . editing_index . borrow ( ) . map ( |( column_index, row_index, is_pinned_column_table) | CellLocation { column_index, row_index, is_pinned_column_table } ) ) ;
662664 let table_response = table
663665 . header ( text_height * 2.0 , |header| {
664666 self . header ( pinned_column_table, header) ;
665667 } )
666668 . body (
667669 self . hovered_row_index ,
668670 search_highlight_row,
669- self . focused_cell ,
671+ focused_cell,
670672 |body| {
671673 self . body (
672674 text_height,
@@ -859,10 +861,12 @@ impl<'array> ArrayTable<'array> {
859861 if editing_index. is_some ( )
860862 && editing_index. unwrap ( ) == ( col_index, row_index, pinned_column_table)
861863 {
864+ focused_changed = true ;
865+ focused_cell = None ;
862866 let ref_mut = & mut * self . editing_value . borrow_mut ( ) ;
863867 let textedit_response = ui. add ( TextEdit :: singleline ( ref_mut) ) ;
864868 if textedit_response. lost_focus ( )
865- || ui. ctx ( ) . input ( |input| input. key_pressed ( Key :: Enter ) )
869+ || ui. ctx ( ) . input_mut ( |input| input. consume_key ( Modifiers :: NONE , Key :: Enter ) )
866870 {
867871 let pointer = PointerKey {
868872 pointer : Self :: pointer_key (
@@ -875,7 +879,13 @@ impl<'array> ArrayTable<'array> {
875879 position : 0 ,
876880 column_id : columns[ col_index] . id ,
877881 } ;
878- updated_value = Some ( ( pointer, mem:: take ( ref_mut) ) )
882+ updated_value = Some ( ( pointer, mem:: take ( ref_mut) ) ) ;
883+ focused_changed = true ;
884+ focused_cell = Some ( CellLocation {
885+ column_index : col_index,
886+ row_index : table_row_index,
887+ is_pinned_column_table : pinned_column_table,
888+ } ) ;
879889 } else {
880890 textedit_response. request_focus ( ) ;
881891 }
@@ -1098,6 +1108,7 @@ impl<'array> ArrayTable<'array> {
10981108 } ;
10991109
11001110 self . edit_cell ( array_response, value_changed, row_index) ;
1111+ self . was_editing = true ;
11011112 }
11021113 if self . hovered_row_index != hover_data. hovered_row {
11031114 self . hovered_row_index = hover_data. hovered_row ;
@@ -1515,6 +1526,28 @@ impl<'array> ArrayTable<'array> {
15151526 self . changed_arrow_vertical_scroll = true ;
15161527 }
15171528 }
1529+ if i. consume_key ( Modifiers :: NONE , Key :: Enter ) && !self . was_editing {
1530+ * self . editing_index . borrow_mut ( ) = Some ( (
1531+ focused_cell. column_index ,
1532+ focused_cell. row_index ,
1533+ focused_cell. is_pinned_column_table ,
1534+ ) ) ;
1535+ let row_index = self . filtered_nodes [ focused_cell. row_index ] ;
1536+ let mut editing_value = String :: new ( ) ;
1537+ let col_index = focused_cell. column_index ;
1538+ let is_pinned_column_table = focused_cell. is_pinned_column_table ;
1539+ {
1540+ let node = self . nodes ( ) . get ( row_index) ;
1541+ if let Some ( row_data) = node. as_ref ( ) {
1542+ let index = self . get_pointer_index_from_cache ( is_pinned_column_table, row_data, col_index, ) ;
1543+ if let Some ( index) = index {
1544+ row_data. entries ( ) [ index] . value . clone ( ) . map ( |v| editing_value = v) ;
1545+ }
1546+ }
1547+ }
1548+
1549+ * self . editing_value . borrow_mut ( ) = editing_value;
1550+ }
15181551 }
15191552 if i. consume_shortcut ( & SHORTCUT_DELETE ) {
15201553 i. events . push ( egui:: Event :: Key {
0 commit comments