Skip to main content

Module pasting

Module pasting 

Source
Expand description

Handlers for text pasted into what is being written that says where it was copied from.

A browser that copies text from a page puts the page’s address on the clipboard beside it, as a kind of its own that nothing takes unless it asks for it (SOURCES): the text itself says nothing of where it is from. So when text is pasted into a new note (see crate::handlers::media, which is where Ctrl+V in the composer goes), the clipboard is asked for that too, and where there is one, whoever pasted is asked what they meant: the text as a passage of that page, marked; or the text alone, as it always was pasted. Nothing is written until that is answered.

flowchart TD
    paste["Ctrl+V, in a new note: text"] --> from{"Does the clipboard say which page it is from?"}
    from -->|"no, or the text is an address itself"| plain["Pasted, as it is"]
    from -->|"yes"| ask{"Asked: as a highlight?"}
    ask -->|"Enter"| marked["Kept beside the text, as the passage the note is about"]
    ask -->|"Backspace"| plain
    ask -->|"Esc"| nothing["Nothing is pasted"]
    marked --> out["Published as a highlight (kind 9802): the passage, the page, and the text as its comment"]

A passage that is marked is not in the text: it shows over it, with the page it is from, and what is written is what is said of it. What goes out is then a highlight (NIP-84; see crate::nostr::compose::highlight), which a client that knows highlights shows as a note quoting the passage, and one that does not shows not at all. It is kept with the draft, and can be taken out again, which leaves a note of its own.

What the browser says is the page as far as it tells: Firefox says only the site (https://example.com) unless it is set to say the whole address (clipboard.copyFullSourceURL, from Firefox 163). The address is shown in the question, and over the text after it.

A reply or a quote is about a note, and is no highlight: text pasted into one is pasted as it is.

Structs§

CopiedFrom
Where what is on the clipboard was copied from, as what copied it says: the address of a page.

Constants§

MAX_SOURCE_CHARS 🔒
How long the address of a page may be and still be taken for one.
SOURCES 🔒
The kinds a browser says the address of the page something was copied from as: Firefox’s, in UTF-16, and Chromium’s.

Functions§

copied_from 🔒
The address bytes say something was copied from, if they say one: of a page on the web, and nothing else. They are text in UTF-16, as Firefox writes it, with or without the mark that says which end first, or in UTF-8; told apart by the zero bytes that an address in UTF-16 is half made of.
quotes_something 🔒
Whether text is worth asking about: there is something in it, and it is not an address by itself, which is no passage of anything.