Skip to content

Commit

Permalink
Generalised codemirror ctrl + enter functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
louispt1 authored and noracato committed Jul 1, 2024
1 parent a755514 commit 5be0fab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 6 additions & 10 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ $(document).on("turbo:load", function () {
viewportMargin: Infinity,
});

// Ctrl+Enter submit on the GQL editor.
if ($(this).attr("name") == "query") {
cm.on("keydown", function (el, event) {
if (event.ctrlKey && event.keyCode === 13) {
$(event.target).parents("form").submit();
}
});

cm.focus();
}
// Ctrl+Enter submit on any CodeMirror instance
cm.on("keydown", function (el, event) {
if (event.ctrlKey && event.keyCode === 13) {
$(event.target).closest("form").submit();
}
});
});

$("#area_code_selector select").change(function (e) {
Expand Down
7 changes: 6 additions & 1 deletion app/views/inspect/scenarios/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
= hno.input :order, as: :text, input_html: { value: user_sortable_list(@scenario.heat_network_order(:lt)) }, label: 'Heat network (LT) dispatchables order', hint: 'Delete all lines to revert to default'
= f.simple_fields_for :households_space_heating_producer_order, @scenario.households_space_heating_producer_order do |hno|
= hno.input :order, as: :text, input_html: { value: user_sortable_list(@scenario.households_space_heating_producer_order) }, label: 'Households space heating producer order', hint: 'Delete all lines to revert to default'
= f.button :submit, class: 'btn btn-primary btn-large'
= content_tag(:button, type: 'submit', class: 'btn btn-primary btn-large') do
Submit
%span.hotkey
%kbd Ctrl
%span.plus +
%kbd

:css
#scenario_heat_network_order_ht_order, #scenario_heat_network_order_mt_order,#scenario_heat_network_order_lt_order,#scenario_forecast_storage_order_order,#scenario_households_space_heating_producer_order_order,#scenario_hydrogen_supply_order_order,#scenario_hydrogen_demand_order_order {
Expand Down

0 comments on commit 5be0fab

Please sign in to comment.