From 8937cc476bb359da6011701b38ebb0ed9e9d1485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guti=C3=A9rrez=20Alonso?= Date: Tue, 22 Aug 2023 00:50:09 +0200 Subject: [PATCH] Adds code for right-click menu for TextEdit Does not work because TextEdit lacks Sense(click) Thought for issue #32 --- .gitignore | 1 + assets/save_file.js | 9 --------- index.html | 1 - src/window.rs | 21 +++++++++++++++++---- 4 files changed, 18 insertions(+), 14 deletions(-) delete mode 100644 assets/save_file.js diff --git a/.gitignore b/.gitignore index 61dd8fe..b5440cc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ **/dist/* .vscode/ **/*.wb +.cargo/config.toml \ No newline at end of file diff --git a/assets/save_file.js b/assets/save_file.js deleted file mode 100644 index a3400a2..0000000 --- a/assets/save_file.js +++ /dev/null @@ -1,9 +0,0 @@ -export function saveFile(filename, content) { - const blob = new Blob([content], { type: "text/plain;charset=utf-8" }); - const url = URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.download = filename; - link.click(); - URL.revokeObjectURL(url); -} \ No newline at end of file diff --git a/index.html b/index.html index f5f0496..eed2bbf 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,6 @@ - diff --git a/src/window.rs b/src/window.rs index d185549..a3bfa5a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -910,16 +910,29 @@ impl MyApp { .show(ui, |my_ui: &mut Ui| { let editor = TextEdit::multiline(&mut self.code) .code_editor() - .desired_width(0.0); + .desired_width(0.0).show(my_ui); - let res = my_ui.add(editor); + let res = editor.response; if self.autosave && res.lost_focus() { debug!("Saving file"); self.saved_feedback = self.auto_save_file(); } - - *editor_focused = res.has_focus().clone(); + + *editor_focused = (&res).has_focus().clone(); + + // FIXME: Does not work because TextEdit is lacking the Sense(click) + // res.context_menu(|ui| { + // if ui.button("Copy").clicked() { + // if let Some(cursor_range) = editor.cursor_range { + // let start = cursor_range.primary.ccursor.index; + // let end = cursor_range.secondary.ccursor.index; + + // let text = &self.code[start..end]; + // ui.output_mut(|o| o.copied_text = String::from(text)); + // } + // } + // }); }); if ui.button(t!("btn.libraries", lang)).clicked() {