Text Editor (technical)

A patch series for COSMIC Text Editor (pop-os/cosmic-edit). Markdown files open rendered, and each Markdown tab can switch between three views. Files open as tabs in the running editor, and the editor brings back every tab of the last session, unsaved changes included. Changed lines are marked in the gutter, changed words are tinted, and an outside change to a file with unsaved changes asks before anything is lost. Markdown is quick to write: a “/” menu of blocks, shortcuts for text styles, links and headings, and list and table editing. On top: Mermaid diagrams, an outline of Markdown headings, JSON tools, visible whitespace and line endings, find and replace with count, extended mode and regex groups, a language per tab, a status bar, Go to line, column selection, code folding, closing many tabs at once, two views side by side, and large files that open fast. The renderer is libcosmic’s native Markdown widget (pulldown-cmark), not a web engine, so the editor starts as fast as before. User overview: text-editor/README.md.

COSMIC Text Editor in Split view

Pages

Page What it covers
Markdown Markdown views and large files, the ”/” command menu, Markdown shortcuts, list editing, tables, links and safety
Search Find and replace, Find All and the Search results panel, Find in Files, Go to line
Tabs and views One editor window, session restore, closing tabs, copy file path and open containing folder, typed and pasted paths, sidebar width, two views, file changed on disk
Editing Changed lines and Compare, whitespace and line endings, language, JSON tools, column selection, folding, selection scrolling, status bar
Development Patch contents: what each patch of the series holds

Installed files

text-editor/build.sh (run by ./install.sh text-editor) reads the upstream commit from the installed package version (the last ~ part), applies text-editor/patches/ to a clone in ~/.cache/edit-md/cosmic-edit, builds it and installs:

Path What
~/.local/bin/cosmic-edit-md The patched editor
~/.local/bin/cosmic-edit Link to it, for launches by name (terminal, scripts)
~/.local/share/applications/com.system76.CosmicEdit.desktop Copy of the system entry pointing at the patched editor (launcher, dock, “Open with”, double-click on a file)
~/.local/state/edit-md/built-commit Upstream commit it was built from
~/.cache/edit-md/cosmic-edit, ~/.cache/edit-md/cosmic-files Upstream source clones

The editor itself writes the session to ~/.local/state/cosmic-edit/session/ (Session restore). Uninstall keeps it.

Commands

./install.sh text-editor               build the installed cosmic-edit version + patches, install per user
./install.sh --uninstall text-editor   back to the system editor
text-editor/build.sh [--uninstall]     the same steps without the installer
text-editor/build.sh --test            apply the patches and run the editor's unit tests, install nothing

Needs the same Rust toolchain as the taskbar, see taskbar. The build takes a few minutes. Only editor windows opened afterwards use it: close and reopen the Text Editor.

Built from the cosmic-edit commit the series was tested on (text-editor/patches/BASE), whatever version is installed: it is a self-contained binary (the cosmic-files checkout follows that commit’s Cargo.lock). A newer cosmic-edit from apt gets one notice during the build and needs no rebuild; ./install.sh --update moves to a newer base when a release of this repo does, and the daily update check (taskbar/check.sh) reminds you if it was not rebuilt. How to move the series to a new version: patch series.

Limits

Upstream

Feature requests: cosmic-edit #247 (Markdown preview), cosmic-edit #94 (session restore), cosmic-edit #495 (file diff). Where this editor is shown upstream and in the community is tracked in #1.