Copy DOM node contents using hints

One of the most powerful features of Conkeror is the ability to use the link hint system not only for links, but for any DOM node. The ability to copy precisely-delimited text without using the mouse or the arrow keys (or their moral equivalent) is fantastic. I don’t think Nyxt offers this yet.

Luckily we do :slight_smile:

https://nyxt.atlas.engineer/article/visual-mode.org

Nyxt’s visual-mode is useful and powerful, and analogous to something else in Conkeror called caret-mode. However, the feature I’m talking about is much more powerful and efficient. It is based on Conkeror’s “browser object” abstraction, which enables all kinds of functionality to be applied to all kinds of DOM elements.

http://conkeror.org/BrowserObjects

http://conkeror.org/WritingBrowserObjectCommands

http://conkeror.org/BrowserObjectDOMNode

The difference in practice is that in Conkeror, if I type * * c, I get prompted to select a DOM node (a table, a list, a textbox, a run of text enclosed within some formatting tag, anything), and then all the visible text within that node is copied to the clipboard. No navigation, no highlighting.

For what you describe, there’s some hacking that one needs to do. But all the pieces are in place already:

  • document-model of every buffer contains the parsed contents of the page opened in it, in the state it is currently in (even if altered by JavaScript).
  • nyxt/web-mode::query-hints's (the arguments are (prompt function &key multi-selection-p annotate-visible-only-p selector)) selector keyword can be used to choose any type ("*", but I’d rather go with a more reasonable selection, as choosing everything is both slow and noisy) of DOM elements and act on them with function argument that takes a list of user-chosen ones (see L314-380 of element-hint.lisp in Nyxt source code for the example of usage).
  • plump:text gives you all the visible text of any document-model node.
  • You can wrap the call to query-hints into a command in your config file and bind it to a key.

With this, you should have a workflow similar to Conkeror one.

Excellent. Thank you @aartaka . It will be some time before I’m informed enough (about Nyxt) and skilled enough (in CL) to be able to put together a PR, but you’ve given me what I will need.

Also, +1 for a constrained list of DOM node types.