diff --git a/core/browser.py b/core/browser.py index 62ce7ad..2cf6fff 100644 --- a/core/browser.py +++ b/core/browser.py @@ -73,6 +73,9 @@ class BrowserView(QWebEngineView): with open(os.path.join(os.path.dirname(__file__), "js", "clear_focus.js"), "r") as f: self.clear_focus_js = f.read() + with open(os.path.join(os.path.dirname(__file__), "js", "select_input_text.js"), "r") as f: + self.select_input_text_js = f.read() + def filter_url(self, url): parsed = urlparse(url) qd = parse_qs(parsed.query, keep_blank_values=True) @@ -253,6 +256,14 @@ class BrowserView(QWebEngineView): def redo_action(self): self.triggerPageAction(self.web_page.Redo) + def select_all(self): + # We need window focus before select all text. + self.web_page.executeJavaScript("window.focus()") + self.triggerPageAction(self.web_page.SelectAll) + + def select_input_text(self): + self.web_page.executeJavaScript(self.select_input_text_js) + def get_url(self): return self.web_page.executeJavaScript("window.location.href;") @@ -670,5 +681,11 @@ class BrowserBuffer(Buffer): else: self.goto_right_tab.emit() + def select_all_or_input_text(self): + if self.is_focus(): + self.buffer_widget.select_input_text() + else: + self.buffer_widget.select_all() + def clear_focus(self): self.buffer_widget.clear_focus() diff --git a/core/js/select_input_text.js b/core/js/select_input_text.js new file mode 100644 index 0000000..5ba29ec --- /dev/null +++ b/core/js/select_input_text.js @@ -0,0 +1,5 @@ +(function() { + const activeElement = document.activeElement; + activeElement.focus(); + activeElement.select(); +})(); diff --git a/eaf.el b/eaf.el index d64f821..e8e5a6a 100644 --- a/eaf.el +++ b/eaf.el @@ -256,6 +256,7 @@ Try not to modify this alist directly. Use `eaf-setq' to modify instead." ("g" . "insert_or_scroll_to_begin") ("x" . "insert_or_close_buffer") ("G" . "insert_or_scroll_to_bottom") + ("C-a" . "select_all_or_input_text") ("M-u" . "clear_focus") ("" . "refresh_page")) "The keybinding of EAF Browser."