| ... | ... | @@ -1143,19 +1143,51 @@ fn queue(input: Input) { |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /// Whether the page takes the key `key` with modifier bits `held` (Shift, Control, Alt, Meta |
| 1146 | | /// from the lowest), rather than leaving it to the browser: the browser keeps its own tab |
| 1147 | | /// and window chords, and pastes through its paste event. |
| 1146 | /// from the lowest), rather than leaving it to the browser. Typing and moving about are the |
| 1147 | /// page's, other chords only where Snowbound binds them; developer tools, view source, |
| 1148 | /// reloading, pasting (through the browser's paste event) and the browser's tab and window |
| 1149 | /// chords always stay the browser's. |
| 1148 | 1150 | #[wasm_bindgen] |
| 1149 | 1151 | pub fn takes(key: &str, held: u8) -> bool { |
| 1150 | | let command = held & if MAC.get() { 8 } else { 2 } != 0; |
| 1151 | | // The browser's own chords take Ctrl or ⌘ without Alt (see `commands::BROWSER`). |
| 1152 | | if !command || held & 4 != 0 { |
| 1152 | let [shift, control, alt, meta] = [1, 2, 4, 8].map(|bit| held & bit != 0); |
| 1153 | let mac = MAC.get(); |
| 1154 | let command = if mac { meta } else { control }; |
| 1155 | let lower = key.to_ascii_lowercase(); |
| 1156 | let tools = if mac { |
| 1157 | meta && alt && matches!(lower.as_str(), "i" | "j" | "c" | "u" | "k") |
| 1158 | } else { |
| 1159 | control && shift && matches!(lower.as_str(), "i" | "j" | "c" | "k") |
| 1160 | || control && lower == "u" |
| 1161 | }; |
| 1162 | let browser = command |
| 1163 | && !alt |
| 1164 | && matches!( |
| 1165 | lower.as_str(), |
| 1166 | "r" | "v" | "w" | "t" | "n" | "q" | "l" | "tab" |
| 1167 | ); |
| 1168 | if tools || browser || matches!(key, "F5" | "F12") { |
| 1169 | return false; |
| 1170 | } |
| 1171 | let function = key |
| 1172 | .strip_prefix('F') |
| 1173 | .is_some_and(|number| number.parse::<u8>().is_ok()); |
| 1174 | // A Mac's Option types characters. |
| 1175 | if !function && !command && (mac || !alt) { |
| 1153 | 1176 | return true; |
| 1154 | 1177 | } |
| 1155 | | !matches!( |
| 1156 | | key.to_ascii_lowercase().as_str(), |
| 1157 | | "v" | "w" | "t" | "n" | "q" | "r" | "l" | "tab" |
| 1158 | | ) |
| 1178 | let pressed = ui::edit_key(&logical_key(key)); |
| 1179 | let modifiers = draw::edit::Modifiers { |
| 1180 | shift, |
| 1181 | control: command, |
| 1182 | option: alt, |
| 1183 | command, |
| 1184 | }; |
| 1185 | // F6 steps between the window's groups and the page. |
| 1186 | key == "F6" |
| 1187 | || commands::find(&pressed, modifiers).is_some() |
| 1188 | || draw::edit::Platform::CURRENT |
| 1189 | .command(&pressed, modifiers) |
| 1190 | .is_some() |
| 1159 | 1191 | } |
| 1160 | 1192 | |
| 1161 | 1193 | /// Reports modifier bits `held` where they changed. |