Skip to content
Snippets Groups Projects
Commit 1020cf3d authored by sam edelsten's avatar sam edelsten
Browse files

prevent clipboard reading password fields

parent 74b06651
No related branches found
No related tags found
No related merge requests found
...@@ -411,12 +411,18 @@ pub(crate) fn input_kb( ...@@ -411,12 +411,18 @@ pub(crate) fn input_kb(
{ {
if let Ok(mut clipboard) = arboard::Clipboard::new() { if let Ok(mut clipboard) = arboard::Clipboard::new() {
if command && keys.just_pressed(KeyCode::C) { if command && keys.just_pressed(KeyCode::C) {
if password_opt.is_some() {
return;
}
if let Some(text) = editor.0.copy_selection() { if let Some(text) = editor.0.copy_selection() {
clipboard.set_text(text).unwrap(); clipboard.set_text(text).unwrap();
return; return;
} }
} }
if command && keys.just_pressed(KeyCode::X) && !readonly { if command && keys.just_pressed(KeyCode::X) && !readonly {
if password_opt.is_some() {
return;
}
if let Some(text) = editor.0.copy_selection() { if let Some(text) = editor.0.copy_selection() {
clipboard.set_text(text).unwrap(); clipboard.set_text(text).unwrap();
editor.0.delete_selection(); editor.0.delete_selection();
...@@ -451,6 +457,9 @@ pub(crate) fn input_kb( ...@@ -451,6 +457,9 @@ pub(crate) fn input_kb(
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
{ {
if command && keys.just_pressed(KeyCode::C) { if command && keys.just_pressed(KeyCode::C) {
if password_opt.is_some() {
return;
}
if let Some(text) = editor.0.copy_selection() { if let Some(text) = editor.0.copy_selection() {
write_clipboard_wasm(text.as_str()); write_clipboard_wasm(text.as_str());
return; return;
...@@ -458,6 +467,9 @@ pub(crate) fn input_kb( ...@@ -458,6 +467,9 @@ pub(crate) fn input_kb(
} }
if command && keys.just_pressed(KeyCode::X) && !readonly { if command && keys.just_pressed(KeyCode::X) && !readonly {
if password_opt.is_some() {
return;
}
if let Some(text) = editor.0.copy_selection() { if let Some(text) = editor.0.copy_selection() {
write_clipboard_wasm(text.as_str()); write_clipboard_wasm(text.as_str());
editor.0.delete_selection(); editor.0.delete_selection();
...@@ -690,6 +702,7 @@ pub fn poll_wasm_paste( ...@@ -690,6 +702,7 @@ pub fn poll_wasm_paste(
&CosmicMaxChars, &CosmicMaxChars,
&CosmicMaxChars, &CosmicMaxChars,
&mut CosmicEditHistory, &mut CosmicEditHistory,
Option<&PasswordInput>,
), ),
Without<ReadOnly>, Without<ReadOnly>,
>, >,
...@@ -700,7 +713,7 @@ pub fn poll_wasm_paste( ...@@ -700,7 +713,7 @@ pub fn poll_wasm_paste(
match inlet { match inlet {
Ok(inlet) => { Ok(inlet) => {
let entity = inlet.entity; let entity = inlet.entity;
if let Ok((mut editor, attrs, max_chars, max_lines, mut edit_history)) = if let Ok((mut editor, attrs, max_chars, max_lines, mut edit_history, password_opt)) =
editor_q.get_mut(entity) editor_q.get_mut(entity)
{ {
let text = inlet.text; let text = inlet.text;
...@@ -712,8 +725,9 @@ pub fn poll_wasm_paste( ...@@ -712,8 +725,9 @@ pub fn poll_wasm_paste(
editor.0.action(&mut font_system.0, Action::Insert(c)); editor.0.action(&mut font_system.0, Action::Insert(c));
} }
} else { } else {
if password_opt.is_some() && char_ev.char.len_utf8() > 1 { if password_opt.is_some() && c.len_utf8() > 1 {
println!("Cannot input multi-byte char '{}' to password field! See https://github.com/StaffEngineer/bevy_cosmic_edit/pull/99#issuecomment-1782607486",char_ev.char); // TODO: console.log here instead
println!("Cannot input multi-byte char '{}' to password field! See https://github.com/StaffEngineer/bevy_cosmic_edit/pull/99#issuecomment-1782607486",c);
continue; continue;
} }
editor.0.action(&mut font_system.0, Action::Insert(c)); editor.0.action(&mut font_system.0, Action::Insert(c));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment