From 65df5c4b059dfc8df204805ecdb663fd18295e92 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Tue, 18 Feb 2020 12:52:06 +0800 Subject: [PATCH] Show content when copy selection text. --- core/browser.py | 6 +++++- core/js/get_selection_text.js | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 core/js/get_selection_text.js diff --git a/core/browser.py b/core/browser.py index 251dc2b..15a0676 100644 --- a/core/browser.py +++ b/core/browser.py @@ -68,6 +68,7 @@ class BrowserView(QWebEngineView): self.clear_focus_js = self.read_js_content("clear_focus.js") self.select_input_text_js = self.read_js_content("select_input_text.js") self.dark_mode_js = self.read_js_content("dark_mode.js") + self.get_selection_text_js = self.read_js_content("get_selection_text.js") def open_download_manage_page(self): self.open_url_new_buffer("file://" + (os.path.join(os.path.dirname(__file__), "aria2-webui", "index.html"))) @@ -212,6 +213,9 @@ class BrowserView(QWebEngineView): def scroll_to_bottom(self): self.eval_js("document.scrollingElement.scrollTo({left: 0, top: document.body.scrollHeight, behavior: '" + self.buffer.emacs_var_dict["eaf-browser-scroll-behavior"] + "'})") + def get_selection_text(self): + return self.execute_js(self.get_selection_text_js) + def refresh_page(self): self.reload() @@ -483,7 +487,7 @@ class BrowserBuffer(Buffer): def copy_text(self): self.buffer_widget.copy_text() - self.message_to_emacs.emit("Copy selected text.") + self.message_to_emacs.emit("Copy '" + self.buffer_widget.get_selection_text() + "'") def yank_text(self): self.buffer_widget.yank_text() diff --git a/core/js/get_selection_text.js b/core/js/get_selection_text.js new file mode 100644 index 0000000..e040fdd --- /dev/null +++ b/core/js/get_selection_text.js @@ -0,0 +1,3 @@ +(function() { + return window.getSelection().toString().substr(0, 20); +})();