diff --git a/web-app/src/components/expr_ast_widget.rs b/web-app/src/components/expr_ast_widget.rs index 66a414e8..b25fae64 100644 --- a/web-app/src/components/expr_ast_widget.rs +++ b/web-app/src/components/expr_ast_widget.rs @@ -61,7 +61,8 @@ impl Component for ExprAstWidget {

{ "Enter Expression:" }

+ init_value={ &self.current_input } + id=""/>
{ &self.last_good_parse }
{ expr_debug } diff --git a/web-app/src/components/expr_entry.rs b/web-app/src/components/expr_entry.rs index 0e10688e..a75f0092 100644 --- a/web-app/src/components/expr_entry.rs +++ b/web-app/src/components/expr_entry.rs @@ -43,6 +43,9 @@ pub struct ExprEntryProps { /// Initial text in text field when it is loaded pub init_value: String, + + /// An ID to use for our strings + pub id: String, } impl Component for ExprEntry { @@ -74,6 +77,7 @@ impl Component for ExprEntry { match void {}, }; + let id_num = format!("{}{}{}", self.id, &"line-number-", &line.to_string()); html! { { line_num_dep_checkbox } @@ -400,7 +410,8 @@ impl ProofWidget { oninput=handle_input onfocus=select_line focus=is_selected_line - init_value=init_value /> + init_value=init_value + id=id_num/> { feedback_and_just_widgets } { action_selector } @@ -496,6 +507,32 @@ impl ProofWidget { // All keyboard shortcuts have the control key held. Do nothing if the // control key isn't pressed. if !key_event.ctrl_key() { + // Change focus on ArrowDown or ArrowUp + if key_event.key() == "ArrowDown" || key_event.key() == "ArrowUp" { + // Get our current id to find the others. + let focused_elem_id = match document().active_element() { + Some(focused_elem_id) => focused_elem_id.id(), + None => return ProofWidgetMsg::Nop, + }; + let up_down = match key_event.key().as_str() { + "ArrowDown" => 1, + "ArrowUp" => -1, + _ => return ProofWidgetMsg::Nop, + }; + let signature = format!("{}{}", self.id, "line-number-"); + let length = signature.chars().count(); + // Verify that our selected element is the one we will work with. + if focused_elem_id.chars().count() < length { + return ProofWidgetMsg::Nop; + } + let num = focused_elem_id[length..].parse::().unwrap() + up_down; + //let new_id = "#line-number-".to_owned() + &num.to_string(); + let _focused_input = match document().get_element_by_id(&format!("{}{}", signature, &num.to_string())) { + Some(_focused_input) => _focused_input.unchecked_into::().focus(), + None => return ProofWidgetMsg::Nop, + }; + } + return ProofWidgetMsg::Nop; } @@ -599,7 +636,9 @@ impl Component for ProofWidget { } }; - let mut tmp = Self { link, prf, pud, selected_line: None, open_error: error, preblob: "".into(), props }; + let id: String = ((random() * 10000.0) as i32).to_string(); + + let mut tmp = Self { link, prf, pud, selected_line: None, open_error: error, preblob: "".into(), props, id }; tmp.update(ProofWidgetMsg::Nop); tmp }