Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/
dist/
.superpowers/
.kiln/tmp/
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="extension/icons/icon-128.png" width="88" alt="">
<img src="app/icons/icon-128.png" width="88" alt="">
</p>

<h1 align="center">Notelet</h1>
Expand Down Expand Up @@ -33,6 +33,8 @@

- **Feels like Notes.** Title, Heading and Body styles, bulleted, dashed, numbered and check lists, pinned notes, Recently Deleted, light and dark themes. In a narrow window it switches to the iPhone layout and its slide between screens.
- **Sprints in one note.** Every sprint and a Backlog live in one Sprints note: a points donut, goals per sprint and per month, drag-and-drop tasks and a rich-text note for each task.
- **Type it plainly, see it typeset.** `->`, `<-`, `==>`, `<=` and friends become →, ←, ⇒, ≤ drawn in JetBrains Mono's style; `--` becomes —, `...` becomes …, and quotes curl. `# `, `- ` and ```` ```php ```` start a heading, a list or a code block, and Ctrl+Z right after gives back what you typed.
- **Code blocks.** Pick the language from the block's corner for syntax colours, copy the block with one click, and copy it with other text to get a Markdown code fence.
- **Keyboard first.** Every button has a shortcut, and you can change any of them.
- **Back and forward.** The mouse's side buttons and Alt+← / Alt+→ step through screens.
- **Private.** Notes stay in one file on your PC. Export a backup file whenever you like.
Expand All @@ -51,7 +53,7 @@ Title, Heading and Subheading, **bold**, *italic*, underline and ~~strikethrough

### The iPhone layout

In a narrow window, such as the popup, Notelet shows one screen at a time and slides between them like iPhone Notes.
In a narrow window, Notelet shows one screen at a time and slides between them like iPhone Notes.

<table>
<tr>
Expand Down Expand Up @@ -80,14 +82,6 @@ Closing the window (X) only hides it; click the tray icon to bring it back. To q

Right-click the tray icon → **Check for updates**. If there is a new version, Notelet asks first, then installs it and reopens. Nothing is lost: any change you are typing is saved first.

## Moving from the Chrome extension

1. In the extension, export a backup (**⋯** above the notes list → **Export**).
2. Install the desktop app.
3. On first start it offers **Import backup**; choose the file. Or use **⋯** → **Import** any time.

Notes, deleted notes, sprints, statuses, settings and custom shortcuts come across. The theme and the notes list width don't; set them again once. You can remove the extension afterwards.

## Back up and restore

Notes live in `%APPDATA%\com.ttncode.notelet\notelet.json`, with the previous save kept beside it as `notelet.json.bak`. If the file is ever damaged, Notelet opens the last good copy, or moves the damaged file aside (it is never deleted) and offers Import. The file stays on this PC only, so export regularly.
Expand Down Expand Up @@ -125,27 +119,29 @@ Press `Ctrl+/` (`⌘/` on Mac) for the full list, grouped by topic. Every button
| Go to the notes list / the note | `Alt+1` / `Alt+3` | `⌥1` / `⌥3` |
| Text styles menu | `Alt+A` | `⌥A` |
| Checklist | `Ctrl+Shift+L` | `⇧⌘L` |
| Block quote | `Ctrl+'` | `⌘'` |
| Move line / duplicate line | `Alt+↑↓` / `Ctrl+Alt+Shift+↑↓` | `⌥↑↓` / `⌘⌥⇧↑↓` |
| Change case: lower, UPPER, Title | `Shift+F3` | `⇧F3` |
| Back / Forward | mouse side buttons, `Alt+←` / `Alt+→` | mouse side buttons, `⌘[` / `⌘]` |
| All shortcuts | `Ctrl+/` | `⌘/` |

`Ctrl+click` (`⌘`-click on Mac) opens a link in a note; a plain click only places the caret.

Text styles follow Notes for Mac with Ctrl in place of Cmd; where Chrome kept a key for itself (Ctrl+N, Ctrl+Shift+T) Notelet uses Alt instead, the same keys as the extension had.
Text styles follow Notes for Mac with Ctrl in place of Cmd. A few actions use Alt instead, such as `Alt+N` for a new note.

**To change a shortcut**, click its key in the list and press the new one. Esc, Tab or a click elsewhere cancels; Backspace removes the key. Keys Windows keeps, and those Chrome kept, are refused; a key another shortcut uses asks before taking it over. ↺ resets one shortcut; **Reset All to Default** resets them all.
**To change a shortcut**, click its key in the list and press the new one. Esc, Tab or a click elsewhere cancels; Backspace removes the key. Keys Windows keeps, and browser keys such as `Ctrl+N`, `Ctrl+T` and `Ctrl+W`, are refused; a key another shortcut uses asks before taking it over. ↺ resets one shortcut; **Reset All to Default** resets them all.

## Development

```bash
npm install
npm test # unit tests for the UI modules
node tools/make-icons.mjs # regenerate icons, then: npx tauri icon desktop/icons/source.png -o desktop/icons
python3 tools/build-arrow-font.py … # rebuild the arrow font; see the script for the steps
npm run tauri dev # run the app (Windows, with Rust and the MSVC build tools)
```

The UI lives in `extension/` and runs unchanged inside the Tauri shell in `desktop/`. CI on Windows runs the unit tests, `cargo test`, clippy, a release build and end-to-end tests that press every shortcut in the built app. Working in WSL, where the Windows toolchain is not available, push a branch and let CI build it.
The UI lives in `app/` (HTML, CSS and plain ES modules, no build step) and runs inside the Tauri shell in `desktop/`. CI on Windows runs the unit tests, `cargo test`, clippy, a release build and end-to-end tests that press every shortcut in the built app. Working in WSL, where the Windows toolchain is not available, push a branch and let CI build it.

Pushing a `v*` tag builds the installer, signs the update, and publishes the release with the `latest.json` the app checks.

Expand Down
14 changes: 4 additions & 10 deletions extension/app.js → app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function main() {
store.onChange(applyRemoteChanges);
openInitialNote();
steps = createNavigation({ readView, showView });
whenShown(document, window, () => showStartupNotice(recovery, loaded.notes.length === 0));
whenShown(document, window, () => showStartupNotice(recovery));
}

// shortcut: an edit typed under SAVE_DELAY_MS before Windows shuts down can be lost, since WebView2
Expand All @@ -120,16 +120,10 @@ function onHistoryKey(event) {
else history.forward();
}

// A damaged notes file is explained once; a first launch with no notes offers the backup from the extension.
function showStartupNotice(recovery, isEmpty) {
// A damaged notes file is explained once.
function showStartupNotice(recovery) {
const message = recoveryMessage(recovery);
if (message) {
showToast(message);
return;
}
if (!isEmpty || state.ui.importOffered) return;
saveUiSoon({ importOffered: true });
showToast("Moving from the Chrome extension? Export a backup there, then choose Import backup.", { label: "Import backup", run: () => importNotes().catch(reportImportError) });
if (message) showToast(message);
}

const toggleMaximize = () => tauri.core.invoke("toggle_maximize").catch((error) => console.error("Notelet: could not resize the window", error));
Expand Down
2 changes: 1 addition & 1 deletion extension/backup.js → app/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function parseBackup(text) {
if (data === undefined) return failure("This file is not a valid backup: it is not JSON.");
if (data?.app !== BACKUP_APP) return failure("This file is not a Notelet backup.");
if (typeof data.version === "number" && data.version > BACKUP_VERSION) {
return failure("This backup comes from a newer version of Notelet. Update the extension, then import again.");
return failure("This backup comes from a newer version of Notelet. Update Notelet, then import again.");
}
if (!SUPPORTED_VERSIONS.has(data.version) || !Array.isArray(data.notes)) return failure("This backup is damaged and cannot be imported.");
if (data.version >= 2 && !isValidSettings(data.settings)) return failure("The status settings in this backup are damaged, so nothing was imported.");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 27 additions & 3 deletions extension/clipboard.js → app/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { codeBlockLines, languageOf } from "./code-block.js";

// What a copy from a note puts on the clipboard. The plain text marks list items the way
// Markdown and Notes do; the HTML keeps the structure but none of the page's colours or sizes,
// so the text takes on the look of wherever it is pasted.
const BLOCKS = new Set(["H1", "H2", "H3", "P", "PRE", "DIV"]);
const BLOCKS = new Set(["H1", "H2", "H3", "P", "PRE", "BLOCKQUOTE", "DIV"]);
const LISTS = new Set(["UL", "OL"]);
const STYLED_LINES = "h1, h2, h3, pre";
const STYLED_LINES = "h1, h2, h3, pre, blockquote";
const NESTED_INDENT = " ";
const HTML_MARKERS = { checked: "☑ ", unchecked: "☐ ", dashed: "– " };
const TEXT_NODE = 3;
Expand All @@ -28,7 +30,29 @@ export function selectedContent(range) {
const styledLineAround = (node) => (node.nodeType === TEXT_NODE ? node.parentElement : node).closest(STYLED_LINES);

export function clipboardText(root) {
return linesOf(root, "").join("\n");
return linesOf(withCodeFences(root), "").join("\n");
}

// Code copied along with other lines is marked as Markdown code, so it stays code where it is
// pasted; code copied on its own stays bare, ready for a terminal.
function withCodeFences(root) {
if ([...root.children].every((block) => block.tagName === "PRE")) return root;
const copy = root.cloneNode(true);
const firstLines = [...copy.children].filter((block) => block.tagName === "PRE" && block.previousElementSibling?.tagName !== "PRE");
for (const firstLine of firstLines) {
const lines = codeBlockLines(firstLine);
const language = languageOf(lines);
if (!language) continue;
firstLine.before(fenceLine(copy, `\`\`\`${language}`));
lines.at(-1).after(fenceLine(copy, "```"));
}
return copy;
}

function fenceLine(root, text) {
const line = root.ownerDocument.createElement("p");
line.textContent = text;
return line;
}

// Notes keep line breaks three ways: separate blocks, <br>, and "\n" inside the text (what a
Expand Down
60 changes: 60 additions & 0 deletions app/code-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// A code block is a run of Monostyled lines (<pre>) next to each other. Its language is kept on
// each line as data-language, so it survives the first line being deleted or moved.
export const CODE_LANGUAGES = [
["", "Plain text"],
["bash", "Bash"],
["css", "CSS"],
["html", "HTML"],
["javascript", "JavaScript"],
["json", "JSON"],
["markdown", "Markdown"],
["php", "PHP"],
["python", "Python"],
["sql", "SQL"],
["typescript", "TypeScript"],
["yaml", "YAML"],
];
const LANGUAGE_IDS = new Set(CODE_LANGUAGES.map(([id]) => id).filter(Boolean));
const FENCE_ALIASES = { js: "javascript", ts: "typescript", sh: "bash", shell: "bash", py: "python", yml: "yaml", md: "markdown" };
const FENCE = /^```([a-z]*)$/i;

export const isCodeLanguage = (id) => LANGUAGE_IDS.has(id);

export function codeBlockLines(line) {
let first = line;
while (first.previousElementSibling?.tagName === "PRE") first = first.previousElementSibling;
const lines = [first];
while (lines.at(-1).nextElementSibling?.tagName === "PRE") lines.push(lines.at(-1).nextElementSibling);
return lines;
}

export const codeBlockFirstLines = (root) => [...root.querySelectorAll("pre")].filter((line) => line.previousElementSibling?.tagName !== "PRE");

export const languageOf = (lines) => lines.map((line) => line.getAttribute("data-language")).find(isCodeLanguage) ?? "";

// An empty language makes the block plain text.
export function setLanguage(lines, language) {
for (const line of lines) {
if (language) line.setAttribute("data-language", language);
else line.removeAttribute("data-language");
}
}

// A line that joins a code block (made Monostyled above it, moved or pasted next to it) takes
// the block's language, so the corner label, the colours and a copy all agree.
export function unifyCodeLanguages(root) {
for (const firstLine of codeBlockFirstLines(root)) {
const lines = codeBlockLines(firstLine);
const language = languageOf(lines);
if (lines.some((line) => (line.getAttribute("data-language") ?? "") !== language)) setLanguage(lines, language);
}
}

// "```" gives "", "```php" or "```js" the language's id; anything else, null.
export function fenceLanguage(text) {
const match = FENCE.exec(text);
if (!match) return null;
const name = match[1].toLowerCase();
const id = FENCE_ALIASES[name] ?? name;
return id === "" || isCodeLanguage(id) ? id : null;
}
104 changes: 104 additions & 0 deletions app/code-highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { codeBlockFirstLines, codeBlockLines, languageOf } from "./code-block.js";

// Syntax colours for code blocks. Prism (vendor/prism.js) finds the tokens; the CSS Custom
// Highlight API colours them without adding any element to the note, so the saved HTML, the
// caret and Undo never see them.

// Prism's token types, folded into the few colours code is shown in.
const TOKEN_GROUPS = {
comment: "comment", prolog: "comment", doctype: "comment", cdata: "comment",
keyword: "keyword", boolean: "keyword", important: "keyword", atrule: "keyword", title: "keyword",
string: "string", char: "string", "attr-value": "string", regex: "string", url: "string",
number: "number", constant: "number",
function: "function", "class-name": "function", builtin: "function",
tag: "tag", selector: "tag", property: "tag", "attr-name": "tag", key: "tag",
variable: "variable",
};
export const HIGHLIGHT_GROUPS = [...new Set(Object.values(TOKEN_GROUPS))];

// The coloured stretches of text, as { group, start, end } offsets. Text inside a token that
// has no colour of its own takes the colour of the token around it.
export function tokenRanges(text, language) {
const grammar = globalThis.Prism?.languages[language];
if (!grammar) return [];
const ranges = [];
collectRanges(globalThis.Prism.tokenize(text, grammar), { start: 0, group: null, ranges });
return ranges;
}

function collectRanges(stream, { start, group, ranges }) {
let offset = start;
for (const token of stream) {
if (typeof token === "string") {
if (group) ranges.push({ group, start: offset, end: offset + token.length });
} else {
collectRanges([].concat(token.content), { start: offset, group: groupOf(token) ?? group, ranges });
}
offset += token.length;
}
}

function groupOf(token) {
const names = [token.type, ...[].concat(token.alias ?? [])];
return names.map((name) => TOKEN_GROUPS[name]).find(Boolean) ?? null;
}

const editorRoots = new Set();
let paintFrame = 0;

// Colours the code in root on the next frame, along with every other editor's code, since the
// page has one set of highlights for all of them.
export function refreshCodeColours(root) {
if (!globalThis.CSS?.highlights || !globalThis.Prism) return;
editorRoots.add(root);
cancelAnimationFrame(paintFrame);
paintFrame = requestAnimationFrame(paintCodeColours);
}

function paintCodeColours() {
const highlights = new Map(HIGHLIGHT_GROUPS.map((group) => [group, new Highlight()]));
for (const root of editorRoots) {
for (const firstLine of codeBlockFirstLines(root)) paintCodeBlock(codeBlockLines(firstLine), highlights);
}
for (const [group, highlight] of highlights) CSS.highlights.set(`code-${group}`, highlight);
}

function paintCodeBlock(lines, highlights) {
const language = languageOf(lines);
if (!language) return;
const { text, pieces } = codeText(lines);
for (const { group, start, end } of tokenRanges(text, language)) {
const range = new Range();
const from = positionAt(pieces, start);
const to = positionAt(pieces, end);
range.setStart(from.node, from.offset);
range.setEnd(to.node, to.offset);
highlights.get(group).add(range);
}
}

// The block's text as Prism reads it, with "\n" for each <br> and between lines, and where each
// text node starts in it.
function codeText(lines) {
let text = "";
const pieces = [];
lines.forEach((line, index) => {
if (index > 0) text += "\n";
const walker = document.createTreeWalker(line, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT);
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
if (node.nodeName === "BR") {
text += "\n";
} else if (node.nodeType === Node.TEXT_NODE) {
pieces.push({ node, start: text.length });
text += node.data;
}
}
});
return { text, pieces };
}

// An offset that falls on a line break moves to the start of the next text.
function positionAt(pieces, offset) {
const piece = pieces.find(({ node, start }) => offset <= start + node.length) ?? pieces.at(-1);
return { node: piece.node, offset: Math.min(Math.max(0, offset - piece.start), piece.node.length) };
}
Loading
Loading