|
1 | 1 | impl SqlEditorWidget { |
| 2 | + fn should_suppress_ctrl_enter_dispatch( |
| 3 | + suppression: &mut EnterKeyupSuppression, |
| 4 | + now: std::time::Instant, |
| 5 | + ) -> bool { |
| 6 | + if matches!( |
| 7 | + *suppression, |
| 8 | + EnterKeyupSuppression::CtrlEnterExecute(previous) |
| 9 | + if now.saturating_duration_since(previous) < CTRL_ENTER_DUPLICATE_WINDOW |
| 10 | + ) { |
| 11 | + return true; |
| 12 | + } |
| 13 | + |
| 14 | + *suppression = EnterKeyupSuppression::CtrlEnterExecute(now); |
| 15 | + false |
| 16 | + } |
| 17 | + |
| 18 | + fn take_enter_keyup_suppression( |
| 19 | + key: Key, |
| 20 | + suppression: &mut EnterKeyupSuppression, |
| 21 | + ) -> bool { |
| 22 | + if !matches!(key, Key::Enter | Key::KPEnter) |
| 23 | + || matches!(*suppression, EnterKeyupSuppression::None) |
| 24 | + { |
| 25 | + return false; |
| 26 | + } |
| 27 | + |
| 28 | + *suppression = EnterKeyupSuppression::None; |
| 29 | + true |
| 30 | + } |
| 31 | + |
2 | 32 | /// Apply a merge produced by [`crate::ui::sql_editor::hangul_repair`] for |
3 | 33 | /// the macOS broken-first-Hangul-key bug. |
4 | 34 | #[cfg(target_os = "macos")] |
@@ -1062,18 +1092,18 @@ impl SqlEditorWidget { |
1062 | 1092 | return true; |
1063 | 1093 | } |
1064 | 1094 | Key::Enter | Key::KPEnter => { |
1065 | | - if matches!( |
1066 | | - *enter_keyup_suppression_for_handle |
| 1095 | + let should_suppress = { |
| 1096 | + let mut suppression = enter_keyup_suppression_for_handle |
1067 | 1097 | .lock() |
1068 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()), |
1069 | | - EnterKeyupSuppression::CtrlEnterExecute |
1070 | | - ) { |
| 1098 | + .unwrap_or_else(|poisoned| poisoned.into_inner()); |
| 1099 | + Self::should_suppress_ctrl_enter_dispatch( |
| 1100 | + &mut suppression, |
| 1101 | + std::time::Instant::now(), |
| 1102 | + ) |
| 1103 | + }; |
| 1104 | + if should_suppress { |
1071 | 1105 | return true; |
1072 | 1106 | } |
1073 | | - *enter_keyup_suppression_for_handle |
1074 | | - .lock() |
1075 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()) = |
1076 | | - EnterKeyupSuppression::CtrlEnterExecute; |
1077 | 1107 | widget_for_shortcuts.execute_statement_at_cursor(); |
1078 | 1108 | return true; |
1079 | 1109 | } |
@@ -1316,6 +1346,16 @@ impl SqlEditorWidget { |
1316 | 1346 | return false; |
1317 | 1347 | } |
1318 | 1348 |
|
| 1349 | + let consume_suppressed_enter_keyup = { |
| 1350 | + let mut suppression = enter_keyup_suppression_for_handle |
| 1351 | + .lock() |
| 1352 | + .unwrap_or_else(|poisoned| poisoned.into_inner()); |
| 1353 | + Self::take_enter_keyup_suppression(key, &mut suppression) |
| 1354 | + }; |
| 1355 | + if consume_suppressed_enter_keyup { |
| 1356 | + return true; |
| 1357 | + } |
| 1358 | + |
1319 | 1359 | if shortcut_modified { |
1320 | 1360 | if popup_visible { |
1321 | 1361 | intellisense_popup_for_handle |
@@ -1395,49 +1435,6 @@ impl SqlEditorWidget { |
1395 | 1435 | } |
1396 | 1436 | } |
1397 | 1437 |
|
1398 | | - if matches!(key, Key::Enter | Key::KPEnter) |
1399 | | - && matches!( |
1400 | | - *enter_keyup_suppression_for_handle |
1401 | | - .lock() |
1402 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()), |
1403 | | - EnterKeyupSuppression::ImeCompositionEnter |
1404 | | - ) |
1405 | | - { |
1406 | | - *enter_keyup_suppression_for_handle |
1407 | | - .lock() |
1408 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()) = |
1409 | | - EnterKeyupSuppression::None; |
1410 | | - return true; |
1411 | | - } |
1412 | | - if matches!(key, Key::Enter | Key::KPEnter) |
1413 | | - && matches!( |
1414 | | - *enter_keyup_suppression_for_handle |
1415 | | - .lock() |
1416 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()), |
1417 | | - EnterKeyupSuppression::PopupConfirm |
1418 | | - ) |
1419 | | - { |
1420 | | - *enter_keyup_suppression_for_handle |
1421 | | - .lock() |
1422 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()) = |
1423 | | - EnterKeyupSuppression::None; |
1424 | | - return true; |
1425 | | - } |
1426 | | - if matches!(key, Key::Enter | Key::KPEnter) |
1427 | | - && matches!( |
1428 | | - *enter_keyup_suppression_for_handle |
1429 | | - .lock() |
1430 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()), |
1431 | | - EnterKeyupSuppression::CtrlEnterExecute |
1432 | | - ) |
1433 | | - { |
1434 | | - *enter_keyup_suppression_for_handle |
1435 | | - .lock() |
1436 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()) = |
1437 | | - EnterKeyupSuppression::None; |
1438 | | - return true; |
1439 | | - } |
1440 | | - |
1441 | 1438 | // Navigation keys - hide popup and let editor handle cursor movement |
1442 | 1439 | if matches!( |
1443 | 1440 | key, |
@@ -1758,18 +1755,18 @@ impl SqlEditorWidget { |
1758 | 1755 | } |
1759 | 1756 |
|
1760 | 1757 | if ctrl_or_cmd && matches!(key, Key::Enter | Key::KPEnter) { |
1761 | | - if matches!( |
1762 | | - *enter_keyup_suppression_for_handle |
| 1758 | + let should_suppress = { |
| 1759 | + let mut suppression = enter_keyup_suppression_for_handle |
1763 | 1760 | .lock() |
1764 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()), |
1765 | | - EnterKeyupSuppression::CtrlEnterExecute |
1766 | | - ) { |
| 1761 | + .unwrap_or_else(|poisoned| poisoned.into_inner()); |
| 1762 | + Self::should_suppress_ctrl_enter_dispatch( |
| 1763 | + &mut suppression, |
| 1764 | + std::time::Instant::now(), |
| 1765 | + ) |
| 1766 | + }; |
| 1767 | + if should_suppress { |
1767 | 1768 | return true; |
1768 | 1769 | } |
1769 | | - *enter_keyup_suppression_for_handle |
1770 | | - .lock() |
1771 | | - .unwrap_or_else(|poisoned| poisoned.into_inner()) = |
1772 | | - EnterKeyupSuppression::CtrlEnterExecute; |
1773 | 1770 | widget_for_shortcuts.execute_statement_at_cursor(); |
1774 | 1771 | return true; |
1775 | 1772 | } |
|
0 commit comments