forked from Mirrors/helix
Compare commits
50 Commits
main
...
change-det
Author | SHA1 | Date |
---|---|---|
trivernis | eda2ae2f18 | 2 years ago |
trivernis | 817c2a7e6d | 2 years ago |
trivernis | 092163bd8f | 2 years ago |
trivernis | 0725aa1046 | 2 years ago |
trivernis | a864b63b0f | 2 years ago |
trivernis | 423435d12a | 2 years ago |
trivernis | dbebd26661 | 2 years ago |
trivernis | c7492aea1f | 2 years ago |
trivernis | 1e1967308d | 2 years ago |
trivernis | c77120433f | 2 years ago |
trivernis | 32079b7ed9 | 2 years ago |
trivernis | 4487f144bd | 2 years ago |
trivernis | 83f81c730a | 2 years ago |
trivernis | 9d1d6a74ec | 2 years ago |
Roland Singer | d839c2a2f5 | 2 years ago |
Roland Singer | 3d987c0703 | 2 years ago |
Roland Singer | 92ebab74b5 | 2 years ago |
Roland Singer | eec845cc34 | 2 years ago |
Roland Singer | 8f43b1f6e9 | 2 years ago |
trivernis | 63a879d156 | 2 years ago |
trivernis | e0b30e0911 | 2 years ago |
trivernis | beeca2d823 | 2 years ago |
trivernis | 6d245dd3d6 | 2 years ago |
trivernis | 233aa1c023 | 2 years ago |
trivernis | 59c0c41a74 | 2 years ago |
trivernis | 9816d82e48 | 2 years ago |
trivernis | 3cec10e1b1 | 2 years ago |
trivernis | 2da81760f5 | 2 years ago |
trivernis | 388181bab7 | 2 years ago |
cossonleo | aec001ad84 | 2 years ago |
trivernis | c24c30584b | 2 years ago |
trivernis | 18b30200cb | 2 years ago |
trivernis | e5ed461ca7 | 2 years ago |
trivernis | de3b54563b | 2 years ago |
cossonleo | 0e04c4c93c | 2 years ago |
trivernis | 117e3b3b55 | 2 years ago |
trivernis | 151ac52741 | 2 years ago |
MDeiml | 90d40b70e8 | 2 years ago |
trivernis | c3c50517ee | 2 years ago |
trivernis | 6f01208a73 | 2 years ago |
trivernis | a6e16df9a3 | 2 years ago |
trivernis | 7cb8330751 | 2 years ago |
Igor Cohanovschi | 9c15d4fade | 2 years ago |
Igor Cohanovschi | 9bd9e4cc42 | 2 years ago |
Igor Cohanovschi | e1bf96f25f | 2 years ago |
cossonleo | 0f4cfa0fe7 | 2 years ago |
cossonleo | 10cd4c56c9 | 2 years ago |
cossonleo | 06a5bca79b | 2 years ago |
cossonleo | 21d4bf859b | 2 years ago |
Carter Green | 46ff498766 | 3 years ago |
@ -1,3 +1,3 @@
|
||||
[alias]
|
||||
xtask = "run --package xtask --"
|
||||
integration-test = "test --features integration --profile integration --workspace --test integration"
|
||||
integration-test = "test --features integration --workspace --test integration"
|
||||
|
@ -1,26 +0,0 @@
|
||||
# Publish the Nix flake outputs to Cachix
|
||||
name: Cachix
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: Publish Flake
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install nix
|
||||
uses: cachix/install-nix-action@v23
|
||||
|
||||
- name: Authenticate with Cachix
|
||||
uses: cachix/cachix-action@v12
|
||||
with:
|
||||
name: helix
|
||||
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||
|
||||
- name: Build nix flake
|
||||
run: nix build -L
|
@ -1,41 +0,0 @@
|
||||
name: Github Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup mdBook
|
||||
uses: peaceiris/actions-mdbook@v1
|
||||
with:
|
||||
mdbook-version: 'latest'
|
||||
# mdbook-version: '0.4.8'
|
||||
|
||||
- run: mdbook build book
|
||||
|
||||
- name: Set output directory
|
||||
run: |
|
||||
OUTDIR=$(basename ${{ github.ref }})
|
||||
echo "OUTDIR=$OUTDIR" >> $GITHUB_ENV
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./book/book
|
||||
destination_dir: ./${{ env.OUTDIR }}
|
||||
|
||||
- name: Deploy stable
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
if: startswith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./book/book
|
@ -0,0 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "1.61.0"
|
||||
components = ["rustfmt", "rust-src"]
|
@ -1,2 +1,5 @@
|
||||
# Things that we don't want ripgrep to search that we do want in git
|
||||
# https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#automatic-filtering
|
||||
|
||||
# Minified JS vendored from mdbook
|
||||
book/theme/highlight.js
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,231 +0,0 @@
|
||||
html {
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
||||
|
||||
.sidebar .sidebar-scrollbox {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.chapter {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.chapter li.chapter-item {
|
||||
line-height: initial;
|
||||
margin: 0;
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.chapter .section li.chapter-item {
|
||||
line-height: inherit;
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
padding: 0 15px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
|
||||
/* 2 1.75 1.5 1.25 1 .875 */
|
||||
.content h1 { font-size: 2em }
|
||||
.content h2 { font-size: 1.75em }
|
||||
.content h3 { font-size: 1.5em }
|
||||
.content h4 { font-size: 1.25em }
|
||||
.content h5 { font-size: 1em }
|
||||
.content h6 { font-size: .875em }
|
||||
|
||||
.content h1,
|
||||
.content h2,
|
||||
.content h3,
|
||||
.content h4 {
|
||||
font-weight: 500;
|
||||
margin-top: 1.275em;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content p,
|
||||
.content ol,
|
||||
.content ul,
|
||||
.content table {
|
||||
margin-top: 0;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content ul li {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
|
||||
.content ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
|
||||
.content ul ul,
|
||||
.content ol ul {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.content li p {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1.5rem 0;
|
||||
padding: 1rem 1.5rem;
|
||||
color: var(--fg);
|
||||
opacity: .9;
|
||||
background-color: var(--quote-bg);
|
||||
border-left: 4px solid var(--quote-border);
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
blockquote *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table thead th {
|
||||
padding: .75rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
table td {
|
||||
padding: .75rem;
|
||||
border: none;
|
||||
}
|
||||
|
||||
table thead tr {
|
||||
border: none;
|
||||
border-bottom: 2px var(--table-border-color) solid;
|
||||
}
|
||||
|
||||
table tbody tr {
|
||||
border-bottom: 1px var(--table-border-line) solid;
|
||||
}
|
||||
|
||||
table tbody tr:nth-child(2n) {
|
||||
background: unset;
|
||||
}
|
||||
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 3px 5px;
|
||||
}
|
||||
|
||||
.colibri {
|
||||
--bg: #3b224c;
|
||||
--fg: #bcbdd0;
|
||||
--heading-fg: #fff;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
/* --links: #a4a0e8; */
|
||||
--links: #ECCDBA;
|
||||
|
||||
--inline-code-color: hsl(48.7, 7.8%, 70%);
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0, 0, 0, .2);
|
||||
|
||||
--quote-bg: #281733;
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 76%);
|
||||
--table-header-bg: hsla(226, 23%, 31%, 0);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
--table-border-line: hsla(201deg, 20%, 92%, 0.2);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #acff5;
|
||||
}
|
||||
|
||||
.colibri .content .header {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* highlight.js theme, :where() is used to avoid increasing specificity */
|
||||
|
||||
:where(.colibri) .hljs {
|
||||
background: #2f1e2e;
|
||||
color: #a39e9b;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-comment,
|
||||
:where(.colibri) .hljs-quote {
|
||||
color: #8d8687;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-link,
|
||||
:where(.colibri) .hljs-meta,
|
||||
:where(.colibri) .hljs-name,
|
||||
:where(.colibri) .hljs-regexp,
|
||||
:where(.colibri) .hljs-selector-class,
|
||||
:where(.colibri) .hljs-selector-id,
|
||||
:where(.colibri) .hljs-tag,
|
||||
:where(.colibri) .hljs-template-variable,
|
||||
:where(.colibri) .hljs-variable {
|
||||
color: #ef6155;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-built_in,
|
||||
:where(.colibri) .hljs-deletion,
|
||||
:where(.colibri) .hljs-literal,
|
||||
:where(.colibri) .hljs-number,
|
||||
:where(.colibri) .hljs-params,
|
||||
:where(.colibri) .hljs-type {
|
||||
color: #f99b15;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-attribute,
|
||||
:where(.colibri) .hljs-section,
|
||||
:where(.colibri) .hljs-title {
|
||||
color: #fec418;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-addition,
|
||||
:where(.colibri) .hljs-bullet,
|
||||
:where(.colibri) .hljs-string,
|
||||
:where(.colibri) .hljs-symbol {
|
||||
color: #48b685;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-keyword,
|
||||
:where(.colibri) .hljs-selector-tag {
|
||||
color: #815ba4;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-strong {
|
||||
font-weight: 700;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# Commands
|
||||
|
||||
Command mode can be activated by pressing `:`. The built-in commands are:
|
||||
Command mode can be activated by pressing `:`, similar to Vim. Built-in commands:
|
||||
|
||||
{{#include ./generated/typable-cmd.md}}
|
||||
|
@ -0,0 +1,75 @@
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| `:quit`, `:q` | Close the current view. |
|
||||
| `:quit!`, `:q!` | Close the current view forcefully (ignoring unsaved changes). |
|
||||
| `:open`, `:o` | Open a file from disk into the current view. |
|
||||
| `:buffer-close`, `:bc`, `:bclose` | Close the current buffer. |
|
||||
| `:buffer-close!`, `:bc!`, `:bclose!` | Close the current buffer forcefully (ignoring unsaved changes). |
|
||||
| `:buffer-close-others`, `:bco`, `:bcloseother` | Close all buffers but the currently focused one. |
|
||||
| `:buffer-close-others!`, `:bco!`, `:bcloseother!` | Close all buffers but the currently focused one. |
|
||||
| `:buffer-close-all`, `:bca`, `:bcloseall` | Close all buffers, without quitting. |
|
||||
| `:buffer-close-all!`, `:bca!`, `:bcloseall!` | Close all buffers forcefully (ignoring unsaved changes), without quitting. |
|
||||
| `:buffer-next`, `:bn`, `:bnext` | Go to next buffer. |
|
||||
| `:buffer-previous`, `:bp`, `:bprev` | Go to previous buffer. |
|
||||
| `:write`, `:w` | Write changes to disk. Accepts an optional path (:write some/path.txt) |
|
||||
| `:write!`, `:w!` | Write changes to disk forcefully (creating necessary subdirectories). Accepts an optional path (:write some/path.txt) |
|
||||
| `:new`, `:n` | Create a new scratch buffer. |
|
||||
| `:format`, `:fmt` | Format the file using the LSP formatter. |
|
||||
| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.) |
|
||||
| `:line-ending` | Set the document's default line ending. Options: crlf, lf. |
|
||||
| `:earlier`, `:ear` | Jump back to an earlier point in edit history. Accepts a number of steps or a time span. |
|
||||
| `:later`, `:lat` | Jump to a later point in edit history. Accepts a number of steps or a time span. |
|
||||
| `:write-quit`, `:wq`, `:x` | Write changes to disk and close the current view. Accepts an optional path (:wq some/path.txt) |
|
||||
| `:write-quit!`, `:wq!`, `:x!` | Write changes to disk and close the current view forcefully. Accepts an optional path (:wq! some/path.txt) |
|
||||
| `:write-all`, `:wa` | Write changes from all buffers to disk. |
|
||||
| `:write-quit-all`, `:wqa`, `:xa` | Write changes from all buffers to disk and close all views. |
|
||||
| `:write-quit-all!`, `:wqa!`, `:xa!` | Write changes from all buffers to disk and close all views forcefully (ignoring unsaved changes). |
|
||||
| `:quit-all`, `:qa` | Close all views. |
|
||||
| `:quit-all!`, `:qa!` | Close all views forcefully (ignoring unsaved changes). |
|
||||
| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
|
||||
| `:cquit!`, `:cq!` | Quit with exit code (default 1) forcefully (ignoring unsaved changes). Accepts an optional integer exit code (:cq! 2). |
|
||||
| `:theme` | Change the editor theme. |
|
||||
| `:clipboard-yank` | Yank main selection into system clipboard. |
|
||||
| `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |
|
||||
| `:primary-clipboard-yank` | Yank main selection into system primary clipboard. |
|
||||
| `:primary-clipboard-yank-join` | Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline. |
|
||||
| `:clipboard-paste-after` | Paste system clipboard after selections. |
|
||||
| `:clipboard-paste-before` | Paste system clipboard before selections. |
|
||||
| `:clipboard-paste-replace` | Replace selections with content of system clipboard. |
|
||||
| `:primary-clipboard-paste-after` | Paste primary clipboard after selections. |
|
||||
| `:primary-clipboard-paste-before` | Paste primary clipboard before selections. |
|
||||
| `:primary-clipboard-paste-replace` | Replace selections with content of system primary clipboard. |
|
||||
| `:show-clipboard-provider` | Show clipboard provider name in status bar. |
|
||||
| `:change-current-directory`, `:cd` | Change the current working directory. |
|
||||
| `:show-directory`, `:pwd` | Show the current working directory. |
|
||||
| `:encoding` | Set encoding based on `https://encoding.spec.whatwg.org` |
|
||||
| `:reload` | Discard changes and reload from the source file. |
|
||||
| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
|
||||
| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
|
||||
| `:debug-remote`, `:dbg-tcp` | Connect to a debug adapter by TCP address and start a debugging session from a given template with given parameters. |
|
||||
| `:debug-eval` | Evaluate expression in current debug context. |
|
||||
| `:vsplit`, `:vs` | Open the file in a vertical split. |
|
||||
| `:vsplit-new`, `:vnew` | Open a scratch buffer in a vertical split. |
|
||||
| `:hsplit`, `:hs`, `:sp` | Open the file in a horizontal split. |
|
||||
| `:hsplit-new`, `:hnew` | Open a scratch buffer in a horizontal split. |
|
||||
| `:tutor` | Open the tutorial. |
|
||||
| `:goto`, `:g` | Go to line number. |
|
||||
| `:set-language`, `:lang` | Set the language of current buffer. |
|
||||
| `:set-option`, `:set` | Set a config option at runtime.<br>For example to disable smart case search, use `:set search.smart-case false`. |
|
||||
| `:get-option`, `:get` | Get the current value of a config option. |
|
||||
| `:sort` | Sort ranges in selection. |
|
||||
| `:rsort` | Sort ranges in selection in reverse order. |
|
||||
| `:reflow` | Hard-wrap the current selection of lines to a given width. |
|
||||
| `:tree-sitter-subtree`, `:ts-subtree` | Display tree sitter subtree under cursor, primarily for debugging queries. |
|
||||
| `:config-reload` | Refreshes helix's config. |
|
||||
| `:config-open` | Open the helix config.toml file. |
|
||||
| `:log-open` | Open the helix log file. |
|
||||
| `:insert-output` | Run shell command, inserting output after each selection. |
|
||||
| `:append-output` | Run shell command, appending output after each selection. |
|
||||
| `:pipe` | Pipe each selection to the shell command. |
|
||||
<<<<<<< HEAD
|
||||
| `:run-shell-command`, `:sh` | Run a shell command |
|
||||
||||||| 4b1fe367
|
||||
=======
|
||||
| `:lsp-restart` | Restarts the LSP server of the current buffer |
|
||||
>>>>>>> lsp-restart
|
@ -1,4 +1,4 @@
|
||||
# Guides
|
||||
|
||||
This section contains guides for adding new language server configurations,
|
||||
tree-sitter grammars, textobject queries, and other similar items.
|
||||
tree-sitter grammars, textobject queries, etc.
|
||||
|
@ -1,53 +1,45 @@
|
||||
# Adding new languages to Helix
|
||||
|
||||
In order to add a new language to Helix, you will need to follow the steps
|
||||
below.
|
||||
# Adding languages
|
||||
|
||||
## Language configuration
|
||||
|
||||
1. Add a new `[[language]]` entry in the `languages.toml` file and provide the
|
||||
necessary configuration for the new language. For more information on
|
||||
language configuration, refer to the
|
||||
[language configuration section](../languages.md) of the documentation.
|
||||
A new language server can be added by extending the `[language-server]` table in the same file.
|
||||
2. If you are adding a new language or updating an existing language server
|
||||
configuration, run the command `cargo xtask docgen` to update the
|
||||
[Language Support](../lang-support.md) documentation.
|
||||
To add a new language, you need to add a `[[language]]` entry to the
|
||||
`languages.toml` (see the [language configuration section]).
|
||||
|
||||
> 💡 If you are adding a new Language Server configuration, make sure to update
|
||||
> the
|
||||
> [Language Server Wiki](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers)
|
||||
> with the installation instructions.
|
||||
When adding a new language or Language Server configuration for an existing
|
||||
language, run `cargo xtask docgen` to add the new configuration to the
|
||||
[Language Support][lang-support] docs before creating a pull request.
|
||||
When adding a Language Server configuration, be sure to update the
|
||||
[Language Server Wiki][install-lsp-wiki] with installation notes.
|
||||
|
||||
## Grammar configuration
|
||||
|
||||
1. If a tree-sitter grammar is available for the new language, add a new
|
||||
`[[grammar]]` entry to the `languages.toml` file.
|
||||
2. If you are testing the grammar locally, you can use the `source.path` key
|
||||
with an absolute path to the grammar. However, before submitting a pull
|
||||
request, make sure to switch to using `source.git`.
|
||||
If a tree-sitter grammar is available for the language, add a new `[[grammar]]`
|
||||
entry to `languages.toml`.
|
||||
|
||||
You may use the `source.path` key rather than `source.git` with an absolute path
|
||||
to a locally available grammar for testing, but switch to `source.git` before
|
||||
submitting a pull request.
|
||||
|
||||
## Queries
|
||||
|
||||
1. In order to provide syntax highlighting and indentation for the new language,
|
||||
you will need to add queries.
|
||||
2. Create a new directory for the language with the path
|
||||
`runtime/queries/<name>/`.
|
||||
3. Refer to the
|
||||
[tree-sitter website](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#queries)
|
||||
for more information on writing queries.
|
||||
|
||||
> 💡 In Helix, the first matching query takes precedence when evaluating
|
||||
> queries, which is different from other editors such as Neovim where the last
|
||||
> matching query supersedes the ones before it. See
|
||||
> [this issue](https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090)
|
||||
> for an example.
|
||||
|
||||
## Common issues
|
||||
|
||||
- If you encounter errors when running Helix after switching branches, you may
|
||||
need to update the tree-sitter grammars. Run the command `hx --grammar fetch`
|
||||
to fetch the grammars and `hx --grammar build` to build any out-of-date
|
||||
grammars.
|
||||
- If a parser is causing a segfault, or you want to remove it, make sure to
|
||||
remove the compiled parser located at `runtime/grammars/<name>.so`.
|
||||
For a language to have syntax-highlighting and indentation among
|
||||
other things, you have to add queries. Add a directory for your
|
||||
language with the path `runtime/queries/<name>/`. The tree-sitter
|
||||
[website](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#queries)
|
||||
gives more info on how to write queries.
|
||||
|
||||
> NOTE: When evaluating queries, the first matching query takes
|
||||
precedence, which is different from other editors like Neovim where
|
||||
the last matching query supersedes the ones before it. See
|
||||
[this issue][neovim-query-precedence] for an example.
|
||||
|
||||
## Common Issues
|
||||
|
||||
- If you get errors when running after switching branches, you may have to update the tree-sitter grammars. Run `hx --grammar fetch` to fetch the grammars and `hx --grammar build` to build any out-of-date grammars.
|
||||
|
||||
- If a parser is segfaulting or you want to remove the parser, make sure to remove the compiled parser in `runtime/grammar/<name>.so`
|
||||
|
||||
[language configuration section]: ../languages.md
|
||||
[neovim-query-precedence]: https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090
|
||||
[install-lsp-wiki]: https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers
|
||||
[lang-support]: ../lang-support.md
|
||||
|
@ -1,296 +1,91 @@
|
||||
# Installing Helix
|
||||
# Installation
|
||||
|
||||
<!--toc:start-->
|
||||
- [Pre-built binaries](#pre-built-binaries)
|
||||
- [Linux, macOS, Windows and OpenBSD packaging status](#linux-macos-windows-and-openbsd-packaging-status)
|
||||
- [Linux](#linux)
|
||||
- [Ubuntu](#ubuntu)
|
||||
- [Fedora/RHEL](#fedorarhel)
|
||||
- [Arch Linux extra](#arch-linux-extra)
|
||||
- [NixOS](#nixos)
|
||||
- [Flatpak](#flatpak)
|
||||
- [Snap](#snap)
|
||||
- [AppImage](#appimage)
|
||||
- [macOS](#macos)
|
||||
- [Homebrew Core](#homebrew-core)
|
||||
- [Windows](#windows)
|
||||
- [Winget](#winget)
|
||||
- [Scoop](#scoop)
|
||||
- [Chocolatey](#chocolatey)
|
||||
- [MSYS2](#msys2)
|
||||
- [Building from source](#building-from-source)
|
||||
- [Configuring Helix's runtime files](#configuring-helixs-runtime-files)
|
||||
- [Linux and macOS](#linux-and-macos)
|
||||
- [Windows](#windows)
|
||||
- [Multiple runtime directories](#multiple-runtime-directories)
|
||||
- [Validating the installation](#validating-the-installation)
|
||||
- [Configure the desktop shortcut](#configure-the-desktop-shortcut)
|
||||
<!--toc:end-->
|
||||
|
||||
To install Helix, follow the instructions specific to your operating system.
|
||||
Note that:
|
||||
|
||||
- To get the latest nightly version of Helix, you need to
|
||||
[build from source](#building-from-source).
|
||||
|
||||
- To take full advantage of Helix, install the language servers for your
|
||||
preferred programming languages. See the
|
||||
[wiki](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers)
|
||||
for instructions.
|
||||
|
||||
## Pre-built binaries
|
||||
|
||||
Download pre-built binaries from the
|
||||
[GitHub Releases page](https://github.com/helix-editor/helix/releases). Add the binary to your system's `$PATH` to use it from the command
|
||||
line.
|
||||
|
||||
## Linux, macOS, Windows and OpenBSD packaging status
|
||||
We provide pre-built binaries on the [GitHub Releases page](https://github.com/helix-editor/helix/releases).
|
||||
|
||||
[![Packaging status](https://repology.org/badge/vertical-allrepos/helix.svg)](https://repology.org/project/helix/versions)
|
||||
|
||||
## Linux
|
||||
|
||||
The following third party repositories are available:
|
||||
|
||||
### Ubuntu
|
||||
## OSX
|
||||
|
||||
Add the `PPA` for Helix:
|
||||
Helix is available in homebrew-core:
|
||||
|
||||
```sh
|
||||
sudo add-apt-repository ppa:maveonair/helix-editor
|
||||
sudo apt update
|
||||
sudo apt install helix
|
||||
```
|
||||
|
||||
### Fedora/RHEL
|
||||
|
||||
Enable the `COPR` repository for Helix:
|
||||
|
||||
```sh
|
||||
sudo dnf copr enable varlad/helix
|
||||
sudo dnf install helix
|
||||
brew install helix
|
||||
```
|
||||
|
||||
### Arch Linux extra
|
||||
|
||||
Releases are available in the `extra` repository:
|
||||
|
||||
```sh
|
||||
sudo pacman -S helix
|
||||
```
|
||||
Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available
|
||||
in the AUR, which builds the master branch.
|
||||
## Linux
|
||||
|
||||
### NixOS
|
||||
|
||||
Helix is available in [nixpkgs](https://github.com/nixos/nixpkgs) through the `helix` attribute,
|
||||
the unstable channel usually carries the latest release.
|
||||
|
||||
Helix is also available as a [flake](https://nixos.wiki/wiki/Flakes) in the project
|
||||
root. Use `nix develop` to spin up a reproducible development shell. Outputs are
|
||||
cached for each push to master using [Cachix](https://www.cachix.org/). The
|
||||
flake is configured to automatically make use of this cache assuming the user
|
||||
accepts the new settings on first use.
|
||||
|
||||
If you are using a version of Nix without flakes enabled,
|
||||
[install Cachix CLI](https://docs.cachix.org/installation) and use
|
||||
`cachix use helix` to configure Nix to use cached outputs when possible.
|
||||
|
||||
### Flatpak
|
||||
|
||||
Helix is available on [Flathub](https://flathub.org/en-GB/apps/com.helix_editor.Helix):
|
||||
|
||||
```sh
|
||||
flatpak install flathub com.helix_editor.Helix
|
||||
flatpak run com.helix_editor.Helix
|
||||
```
|
||||
|
||||
### Snap
|
||||
|
||||
Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with:
|
||||
A [flake](https://nixos.wiki/wiki/Flakes) containing the package is available in
|
||||
the project root. The flake can also be used to spin up a reproducible development
|
||||
shell for working on Helix with `nix develop`.
|
||||
|
||||
```sh
|
||||
snap install --classic helix
|
||||
```
|
||||
|
||||
This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`.
|
||||
Flake outputs are cached for each push to master using
|
||||
[Cachix](https://www.cachix.org/). The flake is configured to
|
||||
automatically make use of this cache assuming the user accepts
|
||||
the new settings on first use.
|
||||
|
||||
### AppImage
|
||||
If you are using a version of Nix without flakes enabled you can
|
||||
[install Cachix cli](https://docs.cachix.org/installation); `cachix use helix` will
|
||||
configure Nix to use cached outputs when possible.
|
||||
|
||||
Install Helix using the Linux [AppImage](https://appimage.org/) format.
|
||||
Download the official Helix AppImage from the [latest releases](https://github.com/helix-editor/helix/releases/latest) page.
|
||||
### Arch Linux
|
||||
|
||||
```sh
|
||||
chmod +x helix-*.AppImage # change permission for executable mode
|
||||
./helix-*.AppImage # run helix
|
||||
```
|
||||
|
||||
## macOS
|
||||
Releases are available in the `community` repository.
|
||||
|
||||
### Homebrew Core
|
||||
A [helix-git](https://aur.archlinux.org/packages/helix-git/) package is also available on the AUR, which builds the master branch.
|
||||
|
||||
```sh
|
||||
brew install helix
|
||||
```
|
||||
### Fedora Linux
|
||||
|
||||
## Windows
|
||||
You can install the COPR package for Helix via
|
||||
|
||||
Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/)
|
||||
or [MSYS2](https://msys2.org/).
|
||||
|
||||
### Winget
|
||||
Windows Package Manager winget command-line tool is by default available on Windows 11 and modern versions of Windows 10 as a part of the App Installer.
|
||||
You can get [App Installer from the Microsoft Store](https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab). If it's already installed, make sure it is updated with the latest version.
|
||||
|
||||
```sh
|
||||
winget install Helix.Helix
|
||||
```
|
||||
|
||||
### Scoop
|
||||
|
||||
```sh
|
||||
scoop install helix
|
||||
sudo dnf copr enable varlad/helix
|
||||
sudo dnf install helix
|
||||
```
|
||||
|
||||
### Chocolatey
|
||||
### Void Linux
|
||||
|
||||
```sh
|
||||
choco install helix
|
||||
```
|
||||
|
||||
### MSYS2
|
||||
|
||||
For 64-bit Windows 8.1 or above:
|
||||
|
||||
```sh
|
||||
pacman -S mingw-w64-ucrt-x86_64-helix
|
||||
sudo xbps-install helix
|
||||
```
|
||||
|
||||
## Building from source
|
||||
|
||||
Requirements:
|
||||
|
||||
Clone the Helix GitHub repository into a directory of your choice. The
|
||||
examples in this documentation assume installation into either `~/src/` on
|
||||
Linux and macOS, or `%userprofile%\src\` on Windows.
|
||||
|
||||
- The [Rust toolchain](https://www.rust-lang.org/tools/install)
|
||||
- The [Git version control system](https://git-scm.com/)
|
||||
- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
|
||||
|
||||
If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
|
||||
## Build from source
|
||||
|
||||
```sh
|
||||
RUSTFLAGS="-C target-feature=-crt-static"
|
||||
```
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
```
|
||||
|
||||
2. Compile from source:
|
||||
|
||||
```sh
|
||||
cargo install --path helix-term --locked
|
||||
```
|
||||
|
||||
This command will create the `hx` executable and construct the tree-sitter
|
||||
grammars in the local `runtime` folder.
|
||||
|
||||
> 💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch
|
||||
> grammars with `hx --grammar fetch` and compile them with
|
||||
> `hx --grammar build`. This will install them in
|
||||
> the `runtime` directory within the user's helix config directory (more
|
||||
> [details below](#multiple-runtime-directories)).
|
||||
|
||||
### Configuring Helix's runtime files
|
||||
|
||||
#### Linux and macOS
|
||||
|
||||
The **runtime** directory is one below the Helix source, so either set a
|
||||
`HELIX_RUNTIME` environment variable to point to that directory and add it to
|
||||
your `~/.bashrc` or equivalent:
|
||||
|
||||
```sh
|
||||
HELIX_RUNTIME=~/src/helix/runtime
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
cargo install --path helix-term
|
||||
```
|
||||
|
||||
Or, create a symbolic link:
|
||||
|
||||
```sh
|
||||
ln -Ts $PWD/runtime ~/.config/helix/runtime
|
||||
```
|
||||
This will install the `hx` binary to `$HOME/.cargo/bin`.
|
||||
|
||||
If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again.
|
||||
Helix also needs it's runtime files so make sure to copy/symlink the `runtime/` directory into the
|
||||
config directory (for example `~/.config/helix/runtime` on Linux/macOS). This location can be overridden
|
||||
via the `HELIX_RUNTIME` environment variable.
|
||||
|
||||
#### Windows
|
||||
| OS | command |
|
||||
|-------------------|-----------|
|
||||
|windows(cmd.exe) |`xcopy /e /i runtime %AppData%/helix/runtime` |
|
||||
|windows(powershell)|`xcopy /e /i runtime $Env:AppData\helix\runtime` |
|
||||
|linux/macos |`ln -s $PWD/runtime ~/.config/helix/runtime`|
|
||||
|
||||
Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for
|
||||
`Edit environment variables for your account`) or use the `setx` command in
|
||||
Cmd:
|
||||
## Finishing up the installation
|
||||
|
||||
```sh
|
||||
setx HELIX_RUNTIME "%userprofile%\source\repos\helix\runtime"
|
||||
To make sure everything is set up as expected you should finally run the helix healthcheck via
|
||||
```
|
||||
|
||||
> 💡 `%userprofile%` resolves to your user directory like
|
||||
> `C:\Users\Your-Name\` for example.
|
||||
|
||||
Or, create a symlink in `%appdata%\helix\` that links to the source code directory:
|
||||
|
||||
| Method | Command |
|
||||
| ---------- | -------------------------------------------------------------------------------------- |
|
||||
| PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` |
|
||||
| Cmd | `cd %appdata%\helix` <br/> `mklink /D runtime "%userprofile%\src\helix\runtime"` |
|
||||
|
||||
> 💡 On Windows, creating a symbolic link may require running PowerShell or
|
||||
> Cmd as an administrator.
|
||||
|
||||
#### Multiple runtime directories
|
||||
|
||||
When Helix finds multiple runtime directories it will search through them for files in the
|
||||
following order:
|
||||
|
||||
1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for
|
||||
developing and testing helix only).
|
||||
2. `runtime/` subdirectory of OS-dependent helix user config directory.
|
||||
3. `$HELIX_RUNTIME`.
|
||||
4. `runtime/` subdirectory of path to Helix executable.
|
||||
|
||||
This order also sets the priority for selecting which file will be used if multiple runtime
|
||||
directories have files with the same name.
|
||||
|
||||
### Validating the installation
|
||||
|
||||
To make sure everything is set up as expected you should run the Helix health
|
||||
check:
|
||||
|
||||
```sh
|
||||
hx --health
|
||||
```
|
||||
For more information on the information displayed in the healthcheck results refer to [Healthcheck](https://github.com/helix-editor/helix/wiki/Healthcheck).
|
||||
|
||||
For more information on the health check results refer to
|
||||
[Health check](https://github.com/helix-editor/helix/wiki/Healthcheck).
|
||||
|
||||
### Configure the desktop shortcut
|
||||
|
||||
If your desktop environment supports the
|
||||
[XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html)
|
||||
you can configure Helix to show up in the application menu by copying the
|
||||
provided `.desktop` and icon files to their correct folders:
|
||||
### Building tree-sitter grammars
|
||||
|
||||
```sh
|
||||
cp contrib/Helix.desktop ~/.local/share/applications
|
||||
cp contrib/helix.png ~/.icons # or ~/.local/share/icons
|
||||
```
|
||||
Tree-sitter grammars must be fetched and compiled if not pre-packaged.
|
||||
Fetch grammars with `hx --grammar fetch` (requires `git`) and compile them
|
||||
with `hx --grammar build` (requires a C++ compiler).
|
||||
|
||||
To use another terminal than the system default, you can modify the `.desktop`
|
||||
file. For example, to use `kitty`:
|
||||
### Installing language servers
|
||||
|
||||
```sh
|
||||
sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop
|
||||
sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop
|
||||
```
|
||||
Language servers can optionally be installed if you want their features (auto-complete, diagnostics etc.).
|
||||
Follow the [instructions on the wiki page](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers) to add your language servers of choice.
|
||||
|
@ -0,0 +1,660 @@
|
||||
"use strict";
|
||||
|
||||
// Fix back button cache problem
|
||||
window.onunload = function () { };
|
||||
|
||||
// Global variable, shared between modules
|
||||
function playground_text(playground) {
|
||||
let code_block = playground.querySelector("code");
|
||||
|
||||
if (window.ace && code_block.classList.contains("editable")) {
|
||||
let editor = window.ace.edit(code_block);
|
||||
return editor.getValue();
|
||||
} else {
|
||||
return code_block.textContent;
|
||||
}
|
||||
}
|
||||
|
||||
(function codeSnippets() {
|
||||
function fetch_with_timeout(url, options, timeout = 6000) {
|
||||
return Promise.race([
|
||||
fetch(url, options),
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout))
|
||||
]);
|
||||
}
|
||||
|
||||
var playgrounds = Array.from(document.querySelectorAll(".playground"));
|
||||
if (playgrounds.length > 0) {
|
||||
fetch_with_timeout("https://play.rust-lang.org/meta/crates", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
// get list of crates available in the rust playground
|
||||
let playground_crates = response.crates.map(item => item["id"]);
|
||||
playgrounds.forEach(block => handle_crate_list_update(block, playground_crates));
|
||||
});
|
||||
}
|
||||
|
||||
function handle_crate_list_update(playground_block, playground_crates) {
|
||||
// update the play buttons after receiving the response
|
||||
update_play_button(playground_block, playground_crates);
|
||||
|
||||
// and install on change listener to dynamically update ACE editors
|
||||
if (window.ace) {
|
||||
let code_block = playground_block.querySelector("code");
|
||||
if (code_block.classList.contains("editable")) {
|
||||
let editor = window.ace.edit(code_block);
|
||||
editor.addEventListener("change", function (e) {
|
||||
update_play_button(playground_block, playground_crates);
|
||||
});
|
||||
// add Ctrl-Enter command to execute rust code
|
||||
editor.commands.addCommand({
|
||||
name: "run",
|
||||
bindKey: {
|
||||
win: "Ctrl-Enter",
|
||||
mac: "Ctrl-Enter"
|
||||
},
|
||||
exec: _editor => run_rust_code(playground_block)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updates the visibility of play button based on `no_run` class and
|
||||
// used crates vs ones available on http://play.rust-lang.org
|
||||
function update_play_button(pre_block, playground_crates) {
|
||||
var play_button = pre_block.querySelector(".play-button");
|
||||
|
||||
// skip if code is `no_run`
|
||||
if (pre_block.querySelector('code').classList.contains("no_run")) {
|
||||
play_button.classList.add("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
// get list of `extern crate`'s from snippet
|
||||
var txt = playground_text(pre_block);
|
||||
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
|
||||
var snippet_crates = [];
|
||||
var item;
|
||||
while (item = re.exec(txt)) {
|
||||
snippet_crates.push(item[1]);
|
||||
}
|
||||
|
||||
// check if all used crates are available on play.rust-lang.org
|
||||
var all_available = snippet_crates.every(function (elem) {
|
||||
return playground_crates.indexOf(elem) > -1;
|
||||
});
|
||||
|
||||
if (all_available) {
|
||||
play_button.classList.remove("hidden");
|
||||
} else {
|
||||
play_button.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function run_rust_code(code_block) {
|
||||
var result_block = code_block.querySelector(".result");
|
||||
if (!result_block) {
|
||||
result_block = document.createElement('code');
|
||||
result_block.className = 'result hljs language-bash';
|
||||
|
||||
code_block.append(result_block);
|
||||
}
|
||||
|
||||
let text = playground_text(code_block);
|
||||
let classes = code_block.querySelector('code').classList;
|
||||
let has_2018 = classes.contains("edition2018");
|
||||
let edition = has_2018 ? "2018" : "2015";
|
||||
|
||||
var params = {
|
||||
version: "stable",
|
||||
optimize: "0",
|
||||
code: text,
|
||||
edition: edition
|
||||
};
|
||||
|
||||
if (text.indexOf("#![feature") !== -1) {
|
||||
params.version = "nightly";
|
||||
}
|
||||
|
||||
result_block.innerText = "Running...";
|
||||
|
||||
fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(params)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => result_block.innerText = response.result)
|
||||
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
|
||||
}
|
||||
|
||||
// Syntax highlighting Configuration
|
||||
hljs.configure({
|
||||
tabReplace: ' ', // 4 spaces
|
||||
languages: [], // Languages used for auto-detection
|
||||
});
|
||||
|
||||
let code_nodes = Array
|
||||
.from(document.querySelectorAll('code'))
|
||||
// Don't highlight `inline code` blocks in headers.
|
||||
.filter(function (node) {return !node.parentElement.classList.contains("header"); });
|
||||
|
||||
if (window.ace) {
|
||||
// language-rust class needs to be removed for editable
|
||||
// blocks or highlightjs will capture events
|
||||
Array
|
||||
.from(document.querySelectorAll('code.editable'))
|
||||
.forEach(function (block) { block.classList.remove('language-rust'); });
|
||||
|
||||
Array
|
||||
.from(document.querySelectorAll('code:not(.editable)'))
|
||||
.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
} else {
|
||||
code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
}
|
||||
|
||||
// Adding the hljs class gives code blocks the color css
|
||||
// even if highlighting doesn't apply
|
||||
code_nodes.forEach(function (block) { block.classList.add('hljs'); });
|
||||
|
||||
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
|
||||
|
||||
var lines = Array.from(block.querySelectorAll('.boring'));
|
||||
// If no lines were hidden, return
|
||||
if (!lines.length) { return; }
|
||||
block.classList.add("hide-boring");
|
||||
|
||||
var buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
buttons.innerHTML = "<button class=\"fa fa-eye\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
|
||||
|
||||
// add expand button
|
||||
var pre_block = block.parentNode;
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
|
||||
pre_block.querySelector('.buttons').addEventListener('click', function (e) {
|
||||
if (e.target.classList.contains('fa-eye')) {
|
||||
e.target.classList.remove('fa-eye');
|
||||
e.target.classList.add('fa-eye-slash');
|
||||
e.target.title = 'Hide lines';
|
||||
e.target.setAttribute('aria-label', e.target.title);
|
||||
|
||||
block.classList.remove('hide-boring');
|
||||
} else if (e.target.classList.contains('fa-eye-slash')) {
|
||||
e.target.classList.remove('fa-eye-slash');
|
||||
e.target.classList.add('fa-eye');
|
||||
e.target.title = 'Show hidden lines';
|
||||
e.target.setAttribute('aria-label', e.target.title);
|
||||
|
||||
block.classList.add('hide-boring');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
Array.from(document.querySelectorAll('pre code')).forEach(function (block) {
|
||||
var pre_block = block.parentNode;
|
||||
if (!pre_block.classList.contains('playground')) {
|
||||
var buttons = pre_block.querySelector(".buttons");
|
||||
if (!buttons) {
|
||||
buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
}
|
||||
|
||||
var clipButton = document.createElement('button');
|
||||
clipButton.className = 'fa fa-copy clip-button';
|
||||
clipButton.title = 'Copy to clipboard';
|
||||
clipButton.setAttribute('aria-label', clipButton.title);
|
||||
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
|
||||
|
||||
buttons.insertBefore(clipButton, buttons.firstChild);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Process playground code blocks
|
||||
Array.from(document.querySelectorAll(".playground")).forEach(function (pre_block) {
|
||||
// Add play button
|
||||
var buttons = pre_block.querySelector(".buttons");
|
||||
if (!buttons) {
|
||||
buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
}
|
||||
|
||||
var runCodeButton = document.createElement('button');
|
||||
runCodeButton.className = 'fa fa-play play-button';
|
||||
runCodeButton.hidden = true;
|
||||
runCodeButton.title = 'Run this code';
|
||||
runCodeButton.setAttribute('aria-label', runCodeButton.title);
|
||||
|
||||
buttons.insertBefore(runCodeButton, buttons.firstChild);
|
||||
runCodeButton.addEventListener('click', function (e) {
|
||||
run_rust_code(pre_block);
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
var copyCodeClipboardButton = document.createElement('button');
|
||||
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
|
||||
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
|
||||
copyCodeClipboardButton.title = 'Copy to clipboard';
|
||||
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
|
||||
|
||||
buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);
|
||||
}
|
||||
|
||||
let code_block = pre_block.querySelector("code");
|
||||
if (window.ace && code_block.classList.contains("editable")) {
|
||||
var undoChangesButton = document.createElement('button');
|
||||
undoChangesButton.className = 'fa fa-history reset-button';
|
||||
undoChangesButton.title = 'Undo changes';
|
||||
undoChangesButton.setAttribute('aria-label', undoChangesButton.title);
|
||||
|
||||
buttons.insertBefore(undoChangesButton, buttons.firstChild);
|
||||
|
||||
undoChangesButton.addEventListener('click', function () {
|
||||
let editor = window.ace.edit(code_block);
|
||||
editor.setValue(editor.originalCode);
|
||||
editor.clearSelection();
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function themes() {
|
||||
var html = document.querySelector('html');
|
||||
var themeToggleButton = document.getElementById('theme-toggle');
|
||||
var themePopup = document.getElementById('theme-list');
|
||||
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
|
||||
var stylesheets = {
|
||||
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
|
||||
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
|
||||
highlight: document.querySelector("[href$='highlight.css']"),
|
||||
};
|
||||
|
||||
function showThemes() {
|
||||
themePopup.style.display = 'block';
|
||||
themeToggleButton.setAttribute('aria-expanded', true);
|
||||
themePopup.querySelector("button#" + get_theme()).focus();
|
||||
}
|
||||
|
||||
function hideThemes() {
|
||||
themePopup.style.display = 'none';
|
||||
themeToggleButton.setAttribute('aria-expanded', false);
|
||||
themeToggleButton.focus();
|
||||
}
|
||||
|
||||
function get_theme() {
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
||||
if (theme === null || theme === undefined) {
|
||||
return default_theme;
|
||||
} else {
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
|
||||
function set_theme(theme, store = true) {
|
||||
let ace_theme;
|
||||
|
||||
if (theme == 'coal' || theme == 'navy') {
|
||||
stylesheets.ayuHighlight.disabled = true;
|
||||
stylesheets.tomorrowNight.disabled = false;
|
||||
stylesheets.highlight.disabled = true;
|
||||
|
||||
ace_theme = "ace/theme/tomorrow_night";
|
||||
} else if (theme == 'ayu') {
|
||||
stylesheets.ayuHighlight.disabled = false;
|
||||
stylesheets.tomorrowNight.disabled = true;
|
||||
stylesheets.highlight.disabled = true;
|
||||
ace_theme = "ace/theme/tomorrow_night";
|
||||
} else {
|
||||
stylesheets.ayuHighlight.disabled = true;
|
||||
stylesheets.tomorrowNight.disabled = true;
|
||||
stylesheets.highlight.disabled = false;
|
||||
ace_theme = "ace/theme/dawn";
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor;
|
||||
}, 1);
|
||||
|
||||
if (window.ace && window.editors) {
|
||||
window.editors.forEach(function (editor) {
|
||||
editor.setTheme(ace_theme);
|
||||
});
|
||||
}
|
||||
|
||||
var previousTheme = get_theme();
|
||||
|
||||
if (store) {
|
||||
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
|
||||
}
|
||||
|
||||
html.classList.remove(previousTheme);
|
||||
html.classList.add(theme);
|
||||
}
|
||||
|
||||
// Set theme
|
||||
var theme = get_theme();
|
||||
|
||||
set_theme(theme, false);
|
||||
|
||||
themeToggleButton.addEventListener('click', function () {
|
||||
if (themePopup.style.display === 'block') {
|
||||
hideThemes();
|
||||
} else {
|
||||
showThemes();
|
||||
}
|
||||
});
|
||||
|
||||
themePopup.addEventListener('click', function (e) {
|
||||
var theme = e.target.id || e.target.parentElement.id;
|
||||
set_theme(theme);
|
||||
});
|
||||
|
||||
themePopup.addEventListener('focusout', function(e) {
|
||||
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
|
||||
if (!!e.relatedTarget && !themeToggleButton.contains(e.relatedTarget) && !themePopup.contains(e.relatedTarget)) {
|
||||
hideThemes();
|
||||
}
|
||||
});
|
||||
|
||||
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
|
||||
document.addEventListener('click', function(e) {
|
||||
if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) {
|
||||
hideThemes();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
||||
if (!themePopup.contains(e.target)) { return; }
|
||||
|
||||
switch (e.key) {
|
||||
case 'Escape':
|
||||
e.preventDefault();
|
||||
hideThemes();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
e.preventDefault();
|
||||
var li = document.activeElement.parentElement;
|
||||
if (li && li.previousElementSibling) {
|
||||
li.previousElementSibling.querySelector('button').focus();
|
||||
}
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
e.preventDefault();
|
||||
var li = document.activeElement.parentElement;
|
||||
if (li && li.nextElementSibling) {
|
||||
li.nextElementSibling.querySelector('button').focus();
|
||||
}
|
||||
break;
|
||||
case 'Home':
|
||||
e.preventDefault();
|
||||
themePopup.querySelector('li:first-child button').focus();
|
||||
break;
|
||||
case 'End':
|
||||
e.preventDefault();
|
||||
themePopup.querySelector('li:last-child button').focus();
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function sidebar() {
|
||||
var html = document.querySelector("html");
|
||||
var sidebar = document.getElementById("sidebar");
|
||||
var sidebarLinks = document.querySelectorAll('#sidebar a');
|
||||
var sidebarToggleButton = document.getElementById("sidebar-toggle");
|
||||
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
|
||||
var firstContact = null;
|
||||
|
||||
function showSidebar() {
|
||||
html.classList.remove('sidebar-hidden')
|
||||
html.classList.add('sidebar-visible');
|
||||
Array.from(sidebarLinks).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', 0);
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', true);
|
||||
sidebar.setAttribute('aria-hidden', false);
|
||||
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
|
||||
}
|
||||
|
||||
|
||||
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
|
||||
|
||||
function toggleSection(ev) {
|
||||
ev.currentTarget.parentElement.classList.toggle('expanded');
|
||||
}
|
||||
|
||||
Array.from(sidebarAnchorToggles).forEach(function (el) {
|
||||
el.addEventListener('click', toggleSection);
|
||||
});
|
||||
|
||||
function hideSidebar() {
|
||||
html.classList.remove('sidebar-visible')
|
||||
html.classList.add('sidebar-hidden');
|
||||
Array.from(sidebarLinks).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', -1);
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', false);
|
||||
sidebar.setAttribute('aria-hidden', true);
|
||||
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
|
||||
}
|
||||
|
||||
// Toggle sidebar
|
||||
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
|
||||
if (html.classList.contains("sidebar-hidden")) {
|
||||
var current_width = parseInt(
|
||||
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
|
||||
if (current_width < 150) {
|
||||
document.documentElement.style.setProperty('--sidebar-width', '150px');
|
||||
}
|
||||
showSidebar();
|
||||
} else if (html.classList.contains("sidebar-visible")) {
|
||||
hideSidebar();
|
||||
} else {
|
||||
if (getComputedStyle(sidebar)['transform'] === 'none') {
|
||||
hideSidebar();
|
||||
} else {
|
||||
showSidebar();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sidebarResizeHandle.addEventListener('mousedown', initResize, false);
|
||||
|
||||
function initResize(e) {
|
||||
window.addEventListener('mousemove', resize, false);
|
||||
window.addEventListener('mouseup', stopResize, false);
|
||||
html.classList.add('sidebar-resizing');
|
||||
}
|
||||
function resize(e) {
|
||||
var pos = (e.clientX - sidebar.offsetLeft);
|
||||
if (pos < 20) {
|
||||
hideSidebar();
|
||||
} else {
|
||||
if (html.classList.contains("sidebar-hidden")) {
|
||||
showSidebar();
|
||||
}
|
||||
pos = Math.min(pos, window.innerWidth - 100);
|
||||
document.documentElement.style.setProperty('--sidebar-width', pos + 'px');
|
||||
}
|
||||
}
|
||||
//on mouseup remove windows functions mousemove & mouseup
|
||||
function stopResize(e) {
|
||||
html.classList.remove('sidebar-resizing');
|
||||
window.removeEventListener('mousemove', resize, false);
|
||||
window.removeEventListener('mouseup', stopResize, false);
|
||||
}
|
||||
|
||||
document.addEventListener('touchstart', function (e) {
|
||||
firstContact = {
|
||||
x: e.touches[0].clientX,
|
||||
time: Date.now()
|
||||
};
|
||||
}, { passive: true });
|
||||
|
||||
document.addEventListener('touchmove', function (e) {
|
||||
if (!firstContact)
|
||||
return;
|
||||
|
||||
var curX = e.touches[0].clientX;
|
||||
var xDiff = curX - firstContact.x,
|
||||
tDiff = Date.now() - firstContact.time;
|
||||
|
||||
if (tDiff < 250 && Math.abs(xDiff) >= 150) {
|
||||
if (xDiff >= 0 && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300))
|
||||
showSidebar();
|
||||
else if (xDiff < 0 && curX < 300)
|
||||
hideSidebar();
|
||||
|
||||
firstContact = null;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
// Scroll sidebar to current active section
|
||||
var activeSection = document.getElementById("sidebar").querySelector(".active");
|
||||
if (activeSection) {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
|
||||
activeSection.scrollIntoView({ block: 'center' });
|
||||
}
|
||||
})();
|
||||
|
||||
(function chapterNavigation() {
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
||||
if (window.search && window.search.hasFocus()) { return; }
|
||||
|
||||
switch (e.key) {
|
||||
case 'ArrowRight':
|
||||
e.preventDefault();
|
||||
var nextButton = document.querySelector('.nav-chapters.next');
|
||||
if (nextButton) {
|
||||
window.location.href = nextButton.href;
|
||||
}
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
e.preventDefault();
|
||||
var previousButton = document.querySelector('.nav-chapters.previous');
|
||||
if (previousButton) {
|
||||
window.location.href = previousButton.href;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function clipboard() {
|
||||
var clipButtons = document.querySelectorAll('.clip-button');
|
||||
|
||||
function hideTooltip(elem) {
|
||||
elem.firstChild.innerText = "";
|
||||
elem.className = 'fa fa-copy clip-button';
|
||||
}
|
||||
|
||||
function showTooltip(elem, msg) {
|
||||
elem.firstChild.innerText = msg;
|
||||
elem.className = 'fa fa-copy tooltipped';
|
||||
}
|
||||
|
||||
var clipboardSnippets = new ClipboardJS('.clip-button', {
|
||||
text: function (trigger) {
|
||||
hideTooltip(trigger);
|
||||
let playground = trigger.closest("pre");
|
||||
return playground_text(playground);
|
||||
}
|
||||
});
|
||||
|
||||
Array.from(clipButtons).forEach(function (clipButton) {
|
||||
clipButton.addEventListener('mouseout', function (e) {
|
||||
hideTooltip(e.currentTarget);
|
||||
});
|
||||
});
|
||||
|
||||
clipboardSnippets.on('success', function (e) {
|
||||
e.clearSelection();
|
||||
showTooltip(e.trigger, "Copied!");
|
||||
});
|
||||
|
||||
clipboardSnippets.on('error', function (e) {
|
||||
showTooltip(e.trigger, "Clipboard error!");
|
||||
});
|
||||
})();
|
||||
|
||||
(function scrollToTop () {
|
||||
var menuTitle = document.querySelector('.menu-title');
|
||||
|
||||
menuTitle.addEventListener('click', function () {
|
||||
document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
});
|
||||
})();
|
||||
|
||||
(function controlMenu() {
|
||||
var menu = document.getElementById('menu-bar');
|
||||
|
||||
(function controlPosition() {
|
||||
var scrollTop = document.scrollingElement.scrollTop;
|
||||
var prevScrollTop = scrollTop;
|
||||
var minMenuY = -menu.clientHeight - 50;
|
||||
// When the script loads, the page can be at any scroll (e.g. if you reforesh it).
|
||||
menu.style.top = scrollTop + 'px';
|
||||
// Same as parseInt(menu.style.top.slice(0, -2), but faster
|
||||
var topCache = menu.style.top.slice(0, -2);
|
||||
menu.classList.remove('sticky');
|
||||
var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster
|
||||
document.addEventListener('scroll', function () {
|
||||
scrollTop = Math.max(document.scrollingElement.scrollTop, 0);
|
||||
// `null` means that it doesn't need to be updated
|
||||
var nextSticky = null;
|
||||
var nextTop = null;
|
||||
var scrollDown = scrollTop > prevScrollTop;
|
||||
var menuPosAbsoluteY = topCache - scrollTop;
|
||||
if (scrollDown) {
|
||||
nextSticky = false;
|
||||
if (menuPosAbsoluteY > 0) {
|
||||
nextTop = prevScrollTop;
|
||||
}
|
||||
} else {
|
||||
if (menuPosAbsoluteY > 0) {
|
||||
nextSticky = true;
|
||||
} else if (menuPosAbsoluteY < minMenuY) {
|
||||
nextTop = prevScrollTop + minMenuY;
|
||||
}
|
||||
}
|
||||
if (nextSticky === true && stickyCache === false) {
|
||||
menu.classList.add('sticky');
|
||||
stickyCache = true;
|
||||
} else if (nextSticky === false && stickyCache === true) {
|
||||
menu.classList.remove('sticky');
|
||||
stickyCache = false;
|
||||
}
|
||||
if (nextTop !== null) {
|
||||
menu.style.top = nextTop + 'px';
|
||||
topCache = nextTop;
|
||||
}
|
||||
prevScrollTop = scrollTop;
|
||||
}, { passive: true });
|
||||
})();
|
||||
(function controlBorder() {
|
||||
menu.classList.remove('bordered');
|
||||
document.addEventListener('scroll', function () {
|
||||
if (menu.offsetTop === 0) {
|
||||
menu.classList.remove('bordered');
|
||||
} else {
|
||||
menu.classList.add('bordered');
|
||||
}
|
||||
}, { passive: true });
|
||||
})();
|
||||
})();
|
@ -0,0 +1,499 @@
|
||||
/* CSS for UI elements (a.k.a. chrome) */
|
||||
|
||||
@import 'variables.css';
|
||||
|
||||
::-webkit-scrollbar {
|
||||
background: var(--bg);
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--scrollbar);
|
||||
}
|
||||
html {
|
||||
scrollbar-color: var(--scrollbar) var(--bg);
|
||||
}
|
||||
#searchresults a,
|
||||
.content a:link,
|
||||
a:visited,
|
||||
a > .hljs {
|
||||
color: var(--links);
|
||||
}
|
||||
.content a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Menu Bar */
|
||||
|
||||
#menu-bar,
|
||||
#menu-bar-hover-placeholder {
|
||||
z-index: 101;
|
||||
margin: auto calc(0px - var(--page-padding));
|
||||
}
|
||||
#menu-bar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
background-color: var(--bg);
|
||||
border-bottom-color: var(--bg);
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
}
|
||||
#menu-bar.sticky,
|
||||
.js #menu-bar-hover-placeholder:hover + #menu-bar,
|
||||
.js #menu-bar:hover,
|
||||
.js.sidebar-visible #menu-bar {
|
||||
position: -webkit-sticky;
|
||||
position: sticky;
|
||||
top: 0 !important;
|
||||
}
|
||||
#menu-bar-hover-placeholder {
|
||||
position: sticky;
|
||||
position: -webkit-sticky;
|
||||
top: 0;
|
||||
height: var(--menu-bar-height);
|
||||
}
|
||||
#menu-bar.bordered {
|
||||
border-bottom-color: var(--table-border-color);
|
||||
}
|
||||
#menu-bar i, #menu-bar .icon-button {
|
||||
position: relative;
|
||||
padding: 0 8px;
|
||||
z-index: 10;
|
||||
line-height: var(--menu-bar-height);
|
||||
cursor: pointer;
|
||||
transition: color 0.5s;
|
||||
}
|
||||
@media only screen and (max-width: 420px) {
|
||||
#menu-bar i, #menu-bar .icon-button {
|
||||
padding: 0 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-button {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: inherit;
|
||||
}
|
||||
.icon-button i {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.right-buttons {
|
||||
margin: 0 15px;
|
||||
}
|
||||
.right-buttons a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.left-buttons {
|
||||
display: flex;
|
||||
margin: 0 5px;
|
||||
}
|
||||
.no-js .left-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
display: inline-block;
|
||||
font-weight: 200;
|
||||
font-size: 2.4rem;
|
||||
line-height: var(--menu-bar-height);
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.js .menu-title {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.menu-bar,
|
||||
.menu-bar:visited,
|
||||
.nav-chapters,
|
||||
.nav-chapters:visited,
|
||||
.mobile-nav-chapters,
|
||||
.mobile-nav-chapters:visited,
|
||||
.menu-bar .icon-button,
|
||||
.menu-bar a i {
|
||||
color: var(--icons);
|
||||
}
|
||||
|
||||
.menu-bar i:hover,
|
||||
.menu-bar .icon-button:hover,
|
||||
.nav-chapters:hover,
|
||||
.mobile-nav-chapters i:hover {
|
||||
color: var(--icons-hover);
|
||||
}
|
||||
|
||||
/* Nav Icons */
|
||||
|
||||
.nav-chapters {
|
||||
font-size: 2.5em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
margin: 0;
|
||||
max-width: 150px;
|
||||
min-width: 90px;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-content: center;
|
||||
flex-direction: column;
|
||||
|
||||
transition: color 0.5s, background-color 0.5s;
|
||||
}
|
||||
|
||||
.nav-chapters:hover {
|
||||
text-decoration: none;
|
||||
background-color: var(--theme-hover);
|
||||
transition: background-color 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.nav-wrapper {
|
||||
margin-top: 50px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-nav-chapters {
|
||||
font-size: 2.5em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
width: 90px;
|
||||
border-radius: 5px;
|
||||
background-color: var(--sidebar-bg);
|
||||
}
|
||||
|
||||
.previous {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.next {
|
||||
float: right;
|
||||
right: var(--page-padding);
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1080px) {
|
||||
.nav-wide-wrapper { display: none; }
|
||||
.nav-wrapper { display: block; }
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1380px) {
|
||||
.sidebar-visible .nav-wide-wrapper { display: none; }
|
||||
.sidebar-visible .nav-wrapper { display: block; }
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
|
||||
:not(pre) > .hljs {
|
||||
display: inline;
|
||||
padding: 0.1em 0.3em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
:not(pre):not(a):not(td):not(p) > .hljs {
|
||||
color: var(--inline-code-color);
|
||||
overflow-x: initial;
|
||||
}
|
||||
|
||||
a:hover > .hljs {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
pre {
|
||||
position: relative;
|
||||
}
|
||||
pre > .buttons {
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
|
||||
color: var(--sidebar-fg);
|
||||
cursor: pointer;
|
||||
}
|
||||
pre > .buttons :hover {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
pre > .buttons i {
|
||||
margin-left: 8px;
|
||||
}
|
||||
pre > .buttons button {
|
||||
color: inherit;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: inherit;
|
||||
}
|
||||
pre > .result {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* Search */
|
||||
|
||||
#searchresults a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
mark {
|
||||
border-radius: 2px;
|
||||
padding: 0 3px 1px 3px;
|
||||
margin: 0 -3px -1px -3px;
|
||||
background-color: var(--search-mark-bg);
|
||||
transition: background-color 300ms linear;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
mark.fade-out {
|
||||
background-color: rgba(0,0,0,0) !important;
|
||||
cursor: auto;
|
||||
}
|
||||
|
||||
.searchbar-outer {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
}
|
||||
|
||||
#searchbar {
|
||||
width: 100%;
|
||||
margin: 5px auto 0px auto;
|
||||
padding: 10px 16px;
|
||||
transition: box-shadow 300ms ease-in-out;
|
||||
border: 1px solid var(--searchbar-border-color);
|
||||
border-radius: 3px;
|
||||
background-color: var(--searchbar-bg);
|
||||
color: var(--searchbar-fg);
|
||||
}
|
||||
#searchbar:focus,
|
||||
#searchbar.active {
|
||||
box-shadow: 0 0 3px var(--searchbar-shadow-color);
|
||||
}
|
||||
|
||||
.searchresults-header {
|
||||
font-weight: bold;
|
||||
font-size: 1em;
|
||||
padding: 18px 0 0 5px;
|
||||
color: var(--searchresults-header-fg);
|
||||
}
|
||||
|
||||
.searchresults-outer {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
border-bottom: 1px dashed var(--searchresults-border-color);
|
||||
}
|
||||
|
||||
ul#searchresults {
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
ul#searchresults li {
|
||||
margin: 10px 0px;
|
||||
padding: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
ul#searchresults li.focus {
|
||||
background-color: var(--searchresults-li-bg);
|
||||
}
|
||||
ul#searchresults span.teaser {
|
||||
display: block;
|
||||
clear: both;
|
||||
margin: 5px 0 0 20px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
ul#searchresults span.teaser em {
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: var(--sidebar-width);
|
||||
font-size: 0.875em;
|
||||
box-sizing: border-box;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior-y: contain;
|
||||
background-color: var(--sidebar-bg);
|
||||
color: var(--sidebar-fg);
|
||||
}
|
||||
.sidebar-resizing {
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.js:not(.sidebar-resizing) .sidebar {
|
||||
transition: transform 0.3s; /* Animation: slide away */
|
||||
}
|
||||
.sidebar code {
|
||||
line-height: 2em;
|
||||
}
|
||||
.sidebar .sidebar-scrollbox {
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
.sidebar .sidebar-resize-handle {
|
||||
position: absolute;
|
||||
cursor: col-resize;
|
||||
width: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
.js .sidebar .sidebar-resize-handle {
|
||||
cursor: col-resize;
|
||||
width: 5px;
|
||||
}
|
||||
.sidebar-hidden .sidebar {
|
||||
transform: translateX(calc(0px - var(--sidebar-width)));
|
||||
}
|
||||
.sidebar::-webkit-scrollbar {
|
||||
background: var(--sidebar-bg);
|
||||
}
|
||||
.sidebar::-webkit-scrollbar-thumb {
|
||||
background: var(--scrollbar);
|
||||
}
|
||||
|
||||
.sidebar-visible .page-wrapper {
|
||||
transform: translateX(var(--sidebar-width));
|
||||
}
|
||||
@media only screen and (min-width: 620px) {
|
||||
.sidebar-visible .page-wrapper {
|
||||
transform: none;
|
||||
margin-left: var(--sidebar-width);
|
||||
}
|
||||
}
|
||||
|
||||
.chapter {
|
||||
list-style: none outside none;
|
||||
padding-left: 0;
|
||||
margin: .25rem 0;
|
||||
}
|
||||
|
||||
.chapter ol {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chapter li {
|
||||
display: flex;
|
||||
color: var(--sidebar-non-existent);
|
||||
}
|
||||
.chapter li a {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: var(--sidebar-fg);
|
||||
}
|
||||
|
||||
.chapter li a:hover {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
|
||||
.chapter li a.active {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
|
||||
.chapter li > a.toggle {
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
padding: 0 10px;
|
||||
user-select: none;
|
||||
opacity: 0.68;
|
||||
}
|
||||
|
||||
.chapter li > a.toggle div {
|
||||
transition: transform 0.5s;
|
||||
}
|
||||
|
||||
/* collapse the section */
|
||||
.chapter li:not(.expanded) + li > ol {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chapter li.chapter-item {
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.chapter .section li.chapter-item {
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
}
|
||||
|
||||
.chapter li.expanded > a.toggle div {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.spacer {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
margin: 5px 0px;
|
||||
}
|
||||
.chapter .spacer {
|
||||
background-color: var(--sidebar-spacer);
|
||||
}
|
||||
|
||||
@media (-moz-touch-enabled: 1), (pointer: coarse) {
|
||||
.chapter li a { padding: 5px 0; }
|
||||
.spacer { margin: 10px 0; }
|
||||
}
|
||||
|
||||
.section {
|
||||
list-style: none outside none;
|
||||
padding-left: 2rem;
|
||||
line-height: 1.9em;
|
||||
}
|
||||
|
||||
/* Theme Menu Popup */
|
||||
|
||||
.theme-popup {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: var(--menu-bar-height);
|
||||
z-index: 1000;
|
||||
border-radius: 4px;
|
||||
font-size: 0.7em;
|
||||
color: var(--fg);
|
||||
background: var(--theme-popup-bg);
|
||||
border: 1px solid var(--theme-popup-border);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: none;
|
||||
}
|
||||
.theme-popup .default {
|
||||
color: var(--icons);
|
||||
}
|
||||
.theme-popup .theme {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 2px 10px;
|
||||
line-height: 25px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
background: inherit;
|
||||
font-size: inherit;
|
||||
}
|
||||
.theme-popup .theme:hover {
|
||||
background-color: var(--theme-hover);
|
||||
}
|
||||
.theme-popup .theme:hover:first-child,
|
||||
.theme-popup .theme:hover:last-child {
|
||||
border-top-left-radius: inherit;
|
||||
border-top-right-radius: inherit;
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
/* Base styles and content styles */
|
||||
|
||||
@import 'variables.css';
|
||||
|
||||
:root {
|
||||
/* Browser default font-size is 16px, this way 1 rem = 10px */
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
/* TODO: replace with self hosted fonts */
|
||||
|
||||
html {
|
||||
font-family: "Inter", sans-serif;
|
||||
color: var(--fg);
|
||||
background-color: var(--bg);
|
||||
text-size-adjust: none;
|
||||
}
|
||||
|
||||
/* @supports (font-variation-settings: normal) { */
|
||||
/* html { font-family: 'Inter var', sans-serif; } */
|
||||
/* } */
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-size: 1.6rem;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace !important;
|
||||
font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
|
||||
}
|
||||
|
||||
/* Don't change font size in headers. */
|
||||
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
|
||||
font-size: unset;
|
||||
}
|
||||
|
||||
.left { float: left; }
|
||||
.right { float: right; }
|
||||
.boring { opacity: 0.6; }
|
||||
.hide-boring .boring { display: none; }
|
||||
.hidden { display: none !important; }
|
||||
|
||||
h2, h3 { margin-top: 2.5em; }
|
||||
h4, h5 { margin-top: 2em; }
|
||||
|
||||
.header + .header h3,
|
||||
.header + .header h4,
|
||||
.header + .header h5 {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
h1:target::before,
|
||||
h2:target::before,
|
||||
h3:target::before,
|
||||
h4:target::before,
|
||||
h5:target::before,
|
||||
h6:target::before {
|
||||
display: inline-block;
|
||||
content: "»";
|
||||
margin-left: -30px;
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
/* This is broken on Safari as of version 14, but is fixed
|
||||
in Safari Technology Preview 117 which I think will be Safari 14.2.
|
||||
https://bugs.webkit.org/show_bug.cgi?id=218076
|
||||
*/
|
||||
:target {
|
||||
scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
|
||||
}
|
||||
|
||||
.page {
|
||||
outline: 0;
|
||||
padding: 0 var(--page-padding);
|
||||
margin-top: calc(0px - var(--menu-bar-height)); /* Compensate for the #menu-bar-hover-placeholder */
|
||||
}
|
||||
.page-wrapper {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.js:not(.sidebar-resizing) .page-wrapper {
|
||||
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
padding: 0 15px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
.content main {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
}
|
||||
|
||||
|
||||
/* 2 1.75 1.5 1.25 1 .875 */
|
||||
|
||||
.content h1 { font-size: 2em }
|
||||
.content h2 { font-size: 1.75em }
|
||||
.content h3 { font-size: 1.5em }
|
||||
.content h4 { font-size: 1.25em }
|
||||
.content h5 { font-size: 1em }
|
||||
.content h6 { font-size: .875em }
|
||||
|
||||
.content h1, .content h2, .content h3, .content h4 {
|
||||
font-weight: 500;
|
||||
margin-top: 1.275em;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
.content p, .content ol, .content ul, .content table {
|
||||
margin-top: 0;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content ul li {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
.content ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
.content ul ul, .content ol ul {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
.content li p {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
.content p { line-height: 1.45em; }
|
||||
.content ol { line-height: 1.45em; }
|
||||
.content ul { line-height: 1.45em; }
|
||||
.content a { text-decoration: none; }
|
||||
.content a:hover { text-decoration: underline; }
|
||||
.content img { max-width: 100%; }
|
||||
.content .header:link,
|
||||
.content .header:visited {
|
||||
color: var(--fg);
|
||||
color: var(--heading-fg);
|
||||
}
|
||||
.content .header:link,
|
||||
.content .header:visited:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
table {
|
||||
margin: 0 auto;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
table td {
|
||||
padding: .75rem;
|
||||
width: auto;
|
||||
}
|
||||
table thead {
|
||||
background: var(--table-header-bg);
|
||||
}
|
||||
table thead td {
|
||||
font-weight: 700;
|
||||
border: none;
|
||||
}
|
||||
table thead th {
|
||||
padding: .75rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
width: auto;
|
||||
}
|
||||
table thead tr {
|
||||
border-bottom: 2px var(--table-border-color) solid;
|
||||
}
|
||||
table tbody tr {
|
||||
border-bottom: 1px var(--table-border-line) solid;
|
||||
}
|
||||
/* Alternate background colors for rows */
|
||||
table tbody tr:nth-child(2n) {
|
||||
/* background: var(--table-alternate-bg); */
|
||||
}
|
||||
|
||||
|
||||
blockquote {
|
||||
margin: 1.5rem 0;
|
||||
padding: 1rem 1.5rem;
|
||||
color: var(--fg);
|
||||
opacity: .9;
|
||||
background-color: var(--quote-bg);
|
||||
border-left: 4px solid var(--quote-border);
|
||||
}
|
||||
blockquote *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
:not(.footnote-definition) + .footnote-definition,
|
||||
.footnote-definition + :not(.footnote-definition) {
|
||||
margin-top: 2em;
|
||||
}
|
||||
.footnote-definition {
|
||||
font-size: 0.9em;
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
.footnote-definition p {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.tooltiptext {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
color: #fff;
|
||||
background-color: #333;
|
||||
transform: translateX(-50%); /* Center by moving tooltip 50% of its width left */
|
||||
left: -8px; /* Half of the width of the icon */
|
||||
top: -35px;
|
||||
font-size: 0.8em;
|
||||
text-align: center;
|
||||
border-radius: 6px;
|
||||
padding: 5px 8px;
|
||||
margin: 5px;
|
||||
z-index: 1000;
|
||||
}
|
||||
.tooltipped .tooltiptext {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.chapter li.part-title {
|
||||
color: var(--sidebar-fg);
|
||||
margin: 5px 0px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.result-no-output {
|
||||
font-style: italic;
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
|
||||
#sidebar,
|
||||
#menu-bar,
|
||||
.nav-chapters,
|
||||
.mobile-nav-chapters {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#page-wrapper.page-wrapper {
|
||||
transform: none;
|
||||
margin-left: 0px;
|
||||
overflow-y: initial;
|
||||
}
|
||||
|
||||
#content {
|
||||
max-width: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.page {
|
||||
overflow-y: initial;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #666666;
|
||||
border-radius: 5px;
|
||||
|
||||
/* Force background to be printed in Chrome */
|
||||
-webkit-print-color-adjust: exact;
|
||||
}
|
||||
|
||||
pre > .buttons {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
a, a:visited, a:active, a:hover {
|
||||
color: #4183c4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
page-break-inside: avoid;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
page-break-inside: avoid;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.fa {
|
||||
display: none !important;
|
||||
}
|
@ -0,0 +1,342 @@
|
||||
|
||||
/* Globals */
|
||||
|
||||
:root {
|
||||
--sidebar-width: 300px;
|
||||
--page-padding: 15px;
|
||||
--content-max-width: 750px;
|
||||
--menu-bar-height: 50px;
|
||||
}
|
||||
|
||||
/* Themes */
|
||||
|
||||
.ayu {
|
||||
--bg: hsl(210, 25%, 8%);
|
||||
--fg: #c5c5c5;
|
||||
|
||||
--sidebar-bg: #14191f;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #5c6773;
|
||||
--sidebar-active: #ffb454;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #0096cf;
|
||||
|
||||
--inline-code-color: #ffb454;
|
||||
|
||||
--theme-popup-bg: #14191f;
|
||||
--theme-popup-border: #5c6773;
|
||||
--theme-hover: #191f26;
|
||||
|
||||
--quote-bg: hsl(226, 15%, 17%);
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(210, 25%, 13%);
|
||||
--table-header-bg: hsl(210, 25%, 28%);
|
||||
--table-alternate-bg: hsl(210, 25%, 11%);
|
||||
|
||||
--searchbar-border-color: #848484;
|
||||
--searchbar-bg: #424242;
|
||||
--searchbar-fg: #fff;
|
||||
--searchbar-shadow-color: #d4c89f;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #252932;
|
||||
--search-mark-bg: #e3b171;
|
||||
}
|
||||
|
||||
.coal {
|
||||
--bg: hsl(200, 7%, 8%);
|
||||
--fg: #98a3ad;
|
||||
|
||||
--sidebar-bg: #292c2f;
|
||||
--sidebar-fg: #a1adb8;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #3473ad;
|
||||
--sidebar-spacer: #393939;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #43484d;
|
||||
--icons-hover: #b3c0cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #141617;
|
||||
--theme-popup-border: #43484d;
|
||||
--theme-hover: #1f2124;
|
||||
|
||||
--quote-bg: hsl(234, 21%, 18%);
|
||||
--quote-border: hsl(234, 21%, 23%);
|
||||
|
||||
--table-border-color: hsl(200, 7%, 13%);
|
||||
--table-header-bg: hsl(200, 7%, 28%);
|
||||
--table-alternate-bg: hsl(200, 7%, 11%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #b7b7b7;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #98a3ad;
|
||||
--searchresults-li-bg: #2b2b2f;
|
||||
--search-mark-bg: #355c7d;
|
||||
}
|
||||
|
||||
.light {
|
||||
--bg: hsl(0, 0%, 100%);
|
||||
--fg: hsl(0, 0%, 0%);
|
||||
|
||||
--sidebar-bg: #fafafa;
|
||||
--sidebar-fg: hsl(0, 0%, 0%);
|
||||
--sidebar-non-existent: #aaaaaa;
|
||||
--sidebar-active: #1f1fff;
|
||||
--sidebar-spacer: #f4f4f4;
|
||||
|
||||
--scrollbar: #8F8F8F;
|
||||
|
||||
--icons: #747474;
|
||||
--icons-hover: #000000;
|
||||
|
||||
--links: #20609f;
|
||||
|
||||
--inline-code-color: #301900;
|
||||
|
||||
--theme-popup-bg: #fafafa;
|
||||
--theme-popup-border: #cccccc;
|
||||
--theme-hover: #e6e6e6;
|
||||
|
||||
--quote-bg: hsl(197, 37%, 96%);
|
||||
--quote-border: hsl(197, 37%, 91%);
|
||||
|
||||
--table-border-color: hsl(0, 0%, 95%);
|
||||
--table-header-bg: hsl(0, 0%, 80%);
|
||||
--table-alternate-bg: hsl(0, 0%, 97%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #fafafa;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #e4f2fe;
|
||||
--search-mark-bg: #a2cff5;
|
||||
}
|
||||
|
||||
.navy {
|
||||
--bg: hsl(226, 23%, 11%);
|
||||
--fg: #bcbdd0;
|
||||
|
||||
--sidebar-bg: #282d3f;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #2b79a2;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: #282e40;
|
||||
|
||||
--quote-bg: hsl(226, 15%, 17%);
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 16%);
|
||||
--table-header-bg: hsl(226, 23%, 31%);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
}
|
||||
|
||||
.rust {
|
||||
--bg: hsl(60, 9%, 87%);
|
||||
--fg: #262625;
|
||||
|
||||
--sidebar-bg: #3b2e2a;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #e69f67;
|
||||
--sidebar-spacer: #45373a;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #262625;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #6e6b5e;
|
||||
|
||||
--theme-popup-bg: #e1e1db;
|
||||
--theme-popup-border: #b38f6b;
|
||||
--theme-hover: #99908a;
|
||||
|
||||
--quote-bg: hsl(60, 5%, 75%);
|
||||
--quote-border: hsl(60, 5%, 70%);
|
||||
|
||||
--table-border-color: hsl(60, 9%, 82%);
|
||||
--table-header-bg: #b3a497;
|
||||
--table-alternate-bg: hsl(60, 9%, 84%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #fafafa;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #dec2a2;
|
||||
--search-mark-bg: #e69f67;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.light.no-js {
|
||||
--bg: hsl(200, 7%, 8%);
|
||||
--fg: #98a3ad;
|
||||
|
||||
--sidebar-bg: #292c2f;
|
||||
--sidebar-fg: #a1adb8;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #3473ad;
|
||||
--sidebar-spacer: #393939;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #43484d;
|
||||
--icons-hover: #b3c0cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #141617;
|
||||
--theme-popup-border: #43484d;
|
||||
--theme-hover: #1f2124;
|
||||
|
||||
--quote-bg: hsl(234, 21%, 18%);
|
||||
--quote-border: hsl(234, 21%, 23%);
|
||||
|
||||
--table-border-color: hsl(200, 7%, 13%);
|
||||
--table-header-bg: hsl(200, 7%, 28%);
|
||||
--table-alternate-bg: hsl(200, 7%, 11%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #b7b7b7;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #98a3ad;
|
||||
--searchresults-li-bg: #2b2b2f;
|
||||
--search-mark-bg: #355c7d;
|
||||
}
|
||||
}
|
||||
|
||||
.colibri {
|
||||
--bg: #3b224c;
|
||||
--fg: #bcbdd0;
|
||||
--heading-fg: #fff;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
/* --links: #a4a0e8; */
|
||||
--links: #ECCDBA;
|
||||
|
||||
--inline-code-color: hsl(48.7, 7.8%, 70%);
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0,0,0, .2);
|
||||
|
||||
--quote-bg: #281733;
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 76%);
|
||||
--table-header-bg: hsla(226, 23%, 31%, 0);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
--table-border-line: hsla(201deg, 20%, 92%, 0.2);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
}
|
||||
|
||||
.colibri {
|
||||
/*
|
||||
--bg: #ffffff;
|
||||
--fg: #452859;
|
||||
--fg: #5a5977;
|
||||
--heading-fg: #281733;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #6F44F0;
|
||||
|
||||
--inline-code-color: #a39e9b;
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0,0,0, .2);
|
||||
|
||||
--quote-bg: rgba(0, 0, 0, 0);
|
||||
--quote-border: hsl(226, 15%, 75%);
|
||||
|
||||
--table-border-color: #5a5977;
|
||||
--table-border-color: hsl(201deg 10% 67%);
|
||||
--table-header-bg: hsl(0, 0%, 100%);
|
||||
--table-alternate-bg: hsl(0, 0%, 97%);
|
||||
--table-border-line: hsl(201deg, 20%, 92%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
*/
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -0,0 +1,56 @@
|
||||
pre code.hljs {
|
||||
display:block;
|
||||
overflow-x:auto;
|
||||
padding:1em
|
||||
}
|
||||
code.hljs {
|
||||
padding:3px 5px
|
||||
}
|
||||
.hljs {
|
||||
background:#2f1e2e;
|
||||
color:#a39e9b
|
||||
}
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color:#8d8687
|
||||
}
|
||||
.hljs-link,
|
||||
.hljs-meta,
|
||||
.hljs-name,
|
||||
.hljs-regexp,
|
||||
.hljs-selector-class,
|
||||
.hljs-selector-id,
|
||||
.hljs-tag,
|
||||
.hljs-template-variable,
|
||||
.hljs-variable {
|
||||
color:#ef6155
|
||||
}
|
||||
.hljs-built_in,
|
||||
.hljs-deletion,
|
||||
.hljs-literal,
|
||||
.hljs-number,
|
||||
.hljs-params,
|
||||
.hljs-type {
|
||||
color:#f99b15
|
||||
}
|
||||
.hljs-attribute,
|
||||
.hljs-section,
|
||||
.hljs-title {
|
||||
color:#fec418
|
||||
}
|
||||
.hljs-addition,
|
||||
.hljs-bullet,
|
||||
.hljs-string,
|
||||
.hljs-symbol {
|
||||
color:#48b685
|
||||
}
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag {
|
||||
color:#815ba4
|
||||
}
|
||||
.hljs-emphasis {
|
||||
font-style:italic
|
||||
}
|
||||
.hljs-strong {
|
||||
font-weight:700
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -1,93 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component type="desktop-application">
|
||||
<id>com.helix_editor.Helix</id>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>MPL-2.0</project_license>
|
||||
<name>Helix</name>
|
||||
<summary>A post-modern text editor</summary>
|
||||
|
||||
<description>
|
||||
<p>
|
||||
Helix is a terminal-based text editor inspired by Kakoune / Neovim and written in Rust.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Vim-like modal editing</li>
|
||||
<li>Multiple selections</li>
|
||||
<li>Built-in language server support</li>
|
||||
<li>Smart, incremental syntax highlighting and code editing via tree-sitter</li>
|
||||
</ul>
|
||||
</description>
|
||||
|
||||
<launchable type="desktop-id">Helix.desktop</launchable>
|
||||
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<caption>Helix with default theme</caption>
|
||||
<image>https://github.com/helix-editor/helix/raw/d4565b4404cabc522bd60822abd374755581d751/screenshot.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
|
||||
<url type="homepage">https://helix-editor.com/</url>
|
||||
<url type="donation">https://opencollective.com/helix-editor</url>
|
||||
<url type="help">https://docs.helix-editor.com/</url>
|
||||
<url type="vcs-browser">https://github.com/helix-editor/helix</url>
|
||||
<url type="bugtracker">https://github.com/helix-editor/helix/issues</url>
|
||||
|
||||
<content_rating type="oars-1.1" />
|
||||
|
||||
<releases>
|
||||
<release version="23.05" date="2023-05-18">
|
||||
<url>https://github.com/helix-editor/helix/releases/tag/23.05</url>
|
||||
</release>
|
||||
<release version="23.03" date="2023-03-31">
|
||||
<url>https://helix-editor.com/news/release-23-03-highlights/</url>
|
||||
</release>
|
||||
<release version="22.12" date="2022-12-6">
|
||||
<url>https://helix-editor.com/news/release-22-12-highlights/</url>
|
||||
</release>
|
||||
<release version="22.08" date="2022-8-31">
|
||||
<url>https://helix-editor.com/news/release-22-08-highlights/</url>
|
||||
</release>
|
||||
<release version="22.05" date="2022-5-28">
|
||||
<url>https://helix-editor.com/news/release-22-05-highlights/</url>
|
||||
</release>
|
||||
<release version="22.03" date="2022-3-28">
|
||||
<url>https://helix-editor.com/news/release-22-03-highlights/</url>
|
||||
</release>
|
||||
</releases>
|
||||
|
||||
<requires>
|
||||
<control>keyboard</control>
|
||||
</requires>
|
||||
|
||||
<categories>
|
||||
<category>Utility</category>
|
||||
<category>TextEditor</category>
|
||||
</categories>
|
||||
|
||||
<keywords>
|
||||
<keyword>text</keyword>
|
||||
<keyword>editor</keyword>
|
||||
<keyword>development</keyword>
|
||||
<keyword>programming</keyword>
|
||||
</keywords>
|
||||
|
||||
<provides>
|
||||
<binary>hx</binary>
|
||||
<mediatype>text/english</mediatype>
|
||||
<mediatype>text/plain</mediatype>
|
||||
<mediatype>text/x-makefile</mediatype>
|
||||
<mediatype>text/x-c++hdr</mediatype>
|
||||
<mediatype>text/x-c++src</mediatype>
|
||||
<mediatype>text/x-chdr</mediatype>
|
||||
<mediatype>text/x-csrc</mediatype>
|
||||
<mediatype>text/x-java</mediatype>
|
||||
<mediatype>text/x-moc</mediatype>
|
||||
<mediatype>text/x-pascal</mediatype>
|
||||
<mediatype>text/x-tcl</mediatype>
|
||||
<mediatype>text/x-tex</mediatype>
|
||||
<mediatype>application/x-shellscript</mediatype>
|
||||
<mediatype>text/x-c</mediatype>
|
||||
<mediatype>text/x-c++</mediatype>
|
||||
</provides>
|
||||
</component>
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 1.8 KiB |
@ -1 +0,0 @@
|
||||
../runtime/themes
|
@ -1,384 +0,0 @@
|
||||
//! The `DocumentFormatter` forms the bridge between the raw document text
|
||||
//! and onscreen positioning. It yields the text graphemes as an iterator
|
||||
//! and traverses (part) of the document text. During that traversal it
|
||||
//! handles grapheme detection, softwrapping and annotations.
|
||||
//! It yields `FormattedGrapheme`s and their corresponding visual coordinates.
|
||||
//!
|
||||
//! As both virtual text and softwrapping can insert additional lines into the document
|
||||
//! it is generally not possible to find the start of the previous visual line.
|
||||
//! Instead the `DocumentFormatter` starts at the last "checkpoint" (usually a linebreak)
|
||||
//! called a "block" and the caller must advance it as needed.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Debug;
|
||||
use std::mem::{replace, take};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
use unicode_segmentation::{Graphemes, UnicodeSegmentation};
|
||||
|
||||
use crate::graphemes::{Grapheme, GraphemeStr};
|
||||
use crate::syntax::Highlight;
|
||||
use crate::text_annotations::TextAnnotations;
|
||||
use crate::{Position, RopeGraphemes, RopeSlice};
|
||||
|
||||
/// TODO make Highlight a u32 to reduce the size of this enum to a single word.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum GraphemeSource {
|
||||
Document {
|
||||
codepoints: u32,
|
||||
},
|
||||
/// Inline virtual text can not be highlighted with a `Highlight` iterator
|
||||
/// because it's not part of the document. Instead the `Highlight`
|
||||
/// is emitted right by the document formatter
|
||||
VirtualText {
|
||||
highlight: Option<Highlight>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FormattedGrapheme<'a> {
|
||||
pub grapheme: Grapheme<'a>,
|
||||
pub source: GraphemeSource,
|
||||
}
|
||||
|
||||
impl<'a> FormattedGrapheme<'a> {
|
||||
pub fn new(
|
||||
g: GraphemeStr<'a>,
|
||||
visual_x: usize,
|
||||
tab_width: u16,
|
||||
source: GraphemeSource,
|
||||
) -> FormattedGrapheme<'a> {
|
||||
FormattedGrapheme {
|
||||
grapheme: Grapheme::new(g, visual_x, tab_width),
|
||||
source,
|
||||
}
|
||||
}
|
||||
/// Returns whether this grapheme is virtual inline text
|
||||
pub fn is_virtual(&self) -> bool {
|
||||
matches!(self.source, GraphemeSource::VirtualText { .. })
|
||||
}
|
||||
|
||||
pub fn placeholder() -> Self {
|
||||
FormattedGrapheme {
|
||||
grapheme: Grapheme::Other { g: " ".into() },
|
||||
source: GraphemeSource::Document { codepoints: 0 },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn doc_chars(&self) -> usize {
|
||||
match self.source {
|
||||
GraphemeSource::Document { codepoints } => codepoints as usize,
|
||||
GraphemeSource::VirtualText { .. } => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_whitespace(&self) -> bool {
|
||||
self.grapheme.is_whitespace()
|
||||
}
|
||||
|
||||
pub fn width(&self) -> usize {
|
||||
self.grapheme.width()
|
||||
}
|
||||
|
||||
pub fn is_word_boundary(&self) -> bool {
|
||||
self.grapheme.is_word_boundary()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TextFormat {
|
||||
pub soft_wrap: bool,
|
||||
pub tab_width: u16,
|
||||
pub max_wrap: u16,
|
||||
pub max_indent_retain: u16,
|
||||
pub wrap_indicator: Box<str>,
|
||||
pub wrap_indicator_highlight: Option<Highlight>,
|
||||
pub viewport_width: u16,
|
||||
}
|
||||
|
||||
// test implementation is basically only used for testing or when softwrap is always disabled
|
||||
impl Default for TextFormat {
|
||||
fn default() -> Self {
|
||||
TextFormat {
|
||||
soft_wrap: false,
|
||||
tab_width: 4,
|
||||
max_wrap: 3,
|
||||
max_indent_retain: 4,
|
||||
wrap_indicator: Box::from(" "),
|
||||
viewport_width: 17,
|
||||
wrap_indicator_highlight: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DocumentFormatter<'t> {
|
||||
text_fmt: &'t TextFormat,
|
||||
annotations: &'t TextAnnotations,
|
||||
|
||||
/// The visual position at the end of the last yielded word boundary
|
||||
visual_pos: Position,
|
||||
graphemes: RopeGraphemes<'t>,
|
||||
/// The character pos of the `graphemes` iter used for inserting annotations
|
||||
char_pos: usize,
|
||||
/// The line pos of the `graphemes` iter used for inserting annotations
|
||||
line_pos: usize,
|
||||
exhausted: bool,
|
||||
|
||||
/// Line breaks to be reserved for virtual text
|
||||
/// at the next line break
|
||||
virtual_lines: usize,
|
||||
inline_anntoation_graphemes: Option<(Graphemes<'t>, Option<Highlight>)>,
|
||||
|
||||
// softwrap specific
|
||||
/// The indentation of the current line
|
||||
/// Is set to `None` if the indentation level is not yet known
|
||||
/// because no non-whitespace graphemes have been encountered yet
|
||||
indent_level: Option<usize>,
|
||||
/// In case a long word needs to be split a single grapheme might need to be wrapped
|
||||
/// while the rest of the word stays on the same line
|
||||
peeked_grapheme: Option<(FormattedGrapheme<'t>, usize)>,
|
||||
/// A first-in first-out (fifo) buffer for the Graphemes of any given word
|
||||
word_buf: Vec<FormattedGrapheme<'t>>,
|
||||
/// The index of the next grapheme that will be yielded from the `word_buf`
|
||||
word_i: usize,
|
||||
}
|
||||
|
||||
impl<'t> DocumentFormatter<'t> {
|
||||
/// Creates a new formatter at the last block before `char_idx`.
|
||||
/// A block is a chunk which always ends with a linebreak.
|
||||
/// This is usually just a normal line break.
|
||||
/// However very long lines are always wrapped at constant intervals that can be cheaply calculated
|
||||
/// to avoid pathological behaviour.
|
||||
pub fn new_at_prev_checkpoint(
|
||||
text: RopeSlice<'t>,
|
||||
text_fmt: &'t TextFormat,
|
||||
annotations: &'t TextAnnotations,
|
||||
char_idx: usize,
|
||||
) -> (Self, usize) {
|
||||
// TODO divide long lines into blocks to avoid bad performance for long lines
|
||||
let block_line_idx = text.char_to_line(char_idx.min(text.len_chars()));
|
||||
let block_char_idx = text.line_to_char(block_line_idx);
|
||||
annotations.reset_pos(block_char_idx);
|
||||
(
|
||||
DocumentFormatter {
|
||||
text_fmt,
|
||||
annotations,
|
||||
visual_pos: Position { row: 0, col: 0 },
|
||||
graphemes: RopeGraphemes::new(text.slice(block_char_idx..)),
|
||||
char_pos: block_char_idx,
|
||||
exhausted: false,
|
||||
virtual_lines: 0,
|
||||
indent_level: None,
|
||||
peeked_grapheme: None,
|
||||
word_buf: Vec::with_capacity(64),
|
||||
word_i: 0,
|
||||
line_pos: block_line_idx,
|
||||
inline_anntoation_graphemes: None,
|
||||
},
|
||||
block_char_idx,
|
||||
)
|
||||
}
|
||||
|
||||
fn next_inline_annotation_grapheme(&mut self) -> Option<(&'t str, Option<Highlight>)> {
|
||||
loop {
|
||||
if let Some(&mut (ref mut annotation, highlight)) =
|
||||
self.inline_anntoation_graphemes.as_mut()
|
||||
{
|
||||
if let Some(grapheme) = annotation.next() {
|
||||
return Some((grapheme, highlight));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((annotation, highlight)) =
|
||||
self.annotations.next_inline_annotation_at(self.char_pos)
|
||||
{
|
||||
self.inline_anntoation_graphemes = Some((
|
||||
UnicodeSegmentation::graphemes(&*annotation.text, true),
|
||||
highlight,
|
||||
))
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn advance_grapheme(&mut self, col: usize) -> Option<FormattedGrapheme<'t>> {
|
||||
let (grapheme, source) =
|
||||
if let Some((grapheme, highlight)) = self.next_inline_annotation_grapheme() {
|
||||
(grapheme.into(), GraphemeSource::VirtualText { highlight })
|
||||
} else if let Some(grapheme) = self.graphemes.next() {
|
||||
self.virtual_lines += self.annotations.annotation_lines_at(self.char_pos);
|
||||
let codepoints = grapheme.len_chars() as u32;
|
||||
|
||||
let overlay = self.annotations.overlay_at(self.char_pos);
|
||||
let grapheme = match overlay {
|
||||
Some((overlay, _)) => overlay.grapheme.as_str().into(),
|
||||
None => Cow::from(grapheme).into(),
|
||||
};
|
||||
|
||||
self.char_pos += codepoints as usize;
|
||||
(grapheme, GraphemeSource::Document { codepoints })
|
||||
} else {
|
||||
if self.exhausted {
|
||||
return None;
|
||||
}
|
||||
self.exhausted = true;
|
||||
// EOF grapheme is required for rendering
|
||||
// and correct position computations
|
||||
return Some(FormattedGrapheme {
|
||||
grapheme: Grapheme::Other { g: " ".into() },
|
||||
source: GraphemeSource::Document { codepoints: 0 },
|
||||
});
|
||||
};
|
||||
|
||||
let grapheme = FormattedGrapheme::new(grapheme, col, self.text_fmt.tab_width, source);
|
||||
|
||||
Some(grapheme)
|
||||
}
|
||||
|
||||
/// Move a word to the next visual line
|
||||
fn wrap_word(&mut self, virtual_lines_before_word: usize) -> usize {
|
||||
// softwrap this word to the next line
|
||||
let indent_carry_over = if let Some(indent) = self.indent_level {
|
||||
if indent as u16 <= self.text_fmt.max_indent_retain {
|
||||
indent as u16
|
||||
} else {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
// ensure the indent stays 0
|
||||
self.indent_level = Some(0);
|
||||
0
|
||||
};
|
||||
|
||||
self.visual_pos.col = indent_carry_over as usize;
|
||||
self.virtual_lines -= virtual_lines_before_word;
|
||||
self.visual_pos.row += 1 + virtual_lines_before_word;
|
||||
let mut i = 0;
|
||||
let mut word_width = 0;
|
||||
let wrap_indicator = UnicodeSegmentation::graphemes(&*self.text_fmt.wrap_indicator, true)
|
||||
.map(|g| {
|
||||
i += 1;
|
||||
let grapheme = FormattedGrapheme::new(
|
||||
g.into(),
|
||||
self.visual_pos.col + word_width,
|
||||
self.text_fmt.tab_width,
|
||||
GraphemeSource::VirtualText {
|
||||
highlight: self.text_fmt.wrap_indicator_highlight,
|
||||
},
|
||||
);
|
||||
word_width += grapheme.width();
|
||||
grapheme
|
||||
});
|
||||
self.word_buf.splice(0..0, wrap_indicator);
|
||||
|
||||
for grapheme in &mut self.word_buf[i..] {
|
||||
let visual_x = self.visual_pos.col + word_width;
|
||||
grapheme
|
||||
.grapheme
|
||||
.change_position(visual_x, self.text_fmt.tab_width);
|
||||
word_width += grapheme.width();
|
||||
}
|
||||
word_width
|
||||
}
|
||||
|
||||
fn advance_to_next_word(&mut self) {
|
||||
self.word_buf.clear();
|
||||
let mut word_width = 0;
|
||||
let virtual_lines_before_word = self.virtual_lines;
|
||||
let mut virtual_lines_before_grapheme = self.virtual_lines;
|
||||
|
||||
loop {
|
||||
// softwrap word if necessary
|
||||
if word_width + self.visual_pos.col >= self.text_fmt.viewport_width as usize {
|
||||
// wrapping this word would move too much text to the next line
|
||||
// split the word at the line end instead
|
||||
if word_width > self.text_fmt.max_wrap as usize {
|
||||
// Usually we stop accomulating graphemes as soon as softwrapping becomes necessary.
|
||||
// However if the last grapheme is multiple columns wide it might extend beyond the EOL.
|
||||
// The condition below ensures that this grapheme is not cutoff and instead wrapped to the next line
|
||||
if word_width + self.visual_pos.col > self.text_fmt.viewport_width as usize {
|
||||
self.peeked_grapheme = self.word_buf.pop().map(|grapheme| {
|
||||
(grapheme, self.virtual_lines - virtual_lines_before_grapheme)
|
||||
});
|
||||
self.virtual_lines = virtual_lines_before_grapheme;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
word_width = self.wrap_word(virtual_lines_before_word);
|
||||
}
|
||||
|
||||
virtual_lines_before_grapheme = self.virtual_lines;
|
||||
|
||||
let grapheme = if let Some((grapheme, virtual_lines)) = self.peeked_grapheme.take() {
|
||||
self.virtual_lines += virtual_lines;
|
||||
grapheme
|
||||
} else if let Some(grapheme) = self.advance_grapheme(self.visual_pos.col + word_width) {
|
||||
grapheme
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Track indentation
|
||||
if !grapheme.is_whitespace() && self.indent_level.is_none() {
|
||||
self.indent_level = Some(self.visual_pos.col);
|
||||
} else if grapheme.grapheme == Grapheme::Newline {
|
||||
self.indent_level = None;
|
||||
}
|
||||
|
||||
let is_word_boundary = grapheme.is_word_boundary();
|
||||
word_width += grapheme.width();
|
||||
self.word_buf.push(grapheme);
|
||||
|
||||
if is_word_boundary {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// returns the document line pos of the **next** grapheme that will be yielded
|
||||
pub fn line_pos(&self) -> usize {
|
||||
self.line_pos
|
||||
}
|
||||
|
||||
/// returns the visual pos of the **next** grapheme that will be yielded
|
||||
pub fn visual_pos(&self) -> Position {
|
||||
self.visual_pos
|
||||
}
|
||||
}
|
||||
|
||||
impl<'t> Iterator for DocumentFormatter<'t> {
|
||||
type Item = (FormattedGrapheme<'t>, Position);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let grapheme = if self.text_fmt.soft_wrap {
|
||||
if self.word_i >= self.word_buf.len() {
|
||||
self.advance_to_next_word();
|
||||
self.word_i = 0;
|
||||
}
|
||||
let grapheme = replace(
|
||||
self.word_buf.get_mut(self.word_i)?,
|
||||
FormattedGrapheme::placeholder(),
|
||||
);
|
||||
self.word_i += 1;
|
||||
grapheme
|
||||
} else {
|
||||
self.advance_grapheme(self.visual_pos.col)?
|
||||
};
|
||||
|
||||
let pos = self.visual_pos;
|
||||
if grapheme.grapheme == Grapheme::Newline {
|
||||
self.visual_pos.row += 1;
|
||||
self.visual_pos.row += take(&mut self.virtual_lines);
|
||||
self.visual_pos.col = 0;
|
||||
self.line_pos += 1;
|
||||
} else {
|
||||
self.visual_pos.col += grapheme.width();
|
||||
}
|
||||
Some((grapheme, pos))
|
||||
}
|
||||
}
|
@ -1,182 +0,0 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::doc_formatter::{DocumentFormatter, TextFormat};
|
||||
use crate::text_annotations::{InlineAnnotation, Overlay, TextAnnotations};
|
||||
|
||||
impl TextFormat {
|
||||
fn new_test(softwrap: bool) -> Self {
|
||||
TextFormat {
|
||||
soft_wrap: softwrap,
|
||||
tab_width: 2,
|
||||
max_wrap: 3,
|
||||
max_indent_retain: 4,
|
||||
wrap_indicator: ".".into(),
|
||||
wrap_indicator_highlight: None,
|
||||
// use a prime number to allow lining up too often with repeat
|
||||
viewport_width: 17,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'t> DocumentFormatter<'t> {
|
||||
fn collect_to_str(&mut self) -> String {
|
||||
use std::fmt::Write;
|
||||
let mut res = String::new();
|
||||
let viewport_width = self.text_fmt.viewport_width;
|
||||
let mut line = 0;
|
||||
|
||||
for (grapheme, pos) in self {
|
||||
if pos.row != line {
|
||||
line += 1;
|
||||
assert_eq!(pos.row, line);
|
||||
write!(res, "\n{}", ".".repeat(pos.col)).unwrap();
|
||||
assert!(
|
||||
pos.col <= viewport_width as usize,
|
||||
"softwrapped failed {}<={viewport_width}",
|
||||
pos.col
|
||||
);
|
||||
}
|
||||
write!(res, "{}", grapheme.grapheme).unwrap();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
fn softwrap_text(text: &str) -> String {
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
text.into(),
|
||||
&TextFormat::new_test(true),
|
||||
&TextAnnotations::default(),
|
||||
0,
|
||||
)
|
||||
.0
|
||||
.collect_to_str()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_softwrap() {
|
||||
assert_eq!(
|
||||
softwrap_text(&"foo ".repeat(10)),
|
||||
"foo foo foo foo \n.foo foo foo foo \n.foo foo "
|
||||
);
|
||||
assert_eq!(
|
||||
softwrap_text(&"fooo ".repeat(10)),
|
||||
"fooo fooo fooo \n.fooo fooo fooo \n.fooo fooo fooo \n.fooo "
|
||||
);
|
||||
|
||||
// check that we don't wrap unnecessarily
|
||||
assert_eq!(softwrap_text("\t\txxxx1xxxx2xx\n"), " xxxx1xxxx2xx \n ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn softwrap_indentation() {
|
||||
assert_eq!(
|
||||
softwrap_text("\t\tfoo1 foo2 foo3 foo4 foo5 foo6\n"),
|
||||
" foo1 foo2 \n.....foo3 foo4 \n.....foo5 foo6 \n "
|
||||
);
|
||||
assert_eq!(
|
||||
softwrap_text("\t\t\tfoo1 foo2 foo3 foo4 foo5 foo6\n"),
|
||||
" foo1 foo2 \n.foo3 foo4 foo5 \n.foo6 \n "
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_word_softwrap() {
|
||||
assert_eq!(
|
||||
softwrap_text("\t\txxxx1xxxx2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxx9xxx\n"),
|
||||
" xxxx1xxxx2xxx\n.....x3xxxx4xxxx5\n.....xxxx6xxxx7xx\n.....xx8xxxx9xxx \n "
|
||||
);
|
||||
assert_eq!(
|
||||
softwrap_text("xxxxxxxx1xxxx2xxx\n"),
|
||||
"xxxxxxxx1xxxx2xxx\n. \n "
|
||||
);
|
||||
assert_eq!(
|
||||
softwrap_text("\t\txxxx1xxxx 2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxx9xxx\n"),
|
||||
" xxxx1xxxx \n.....2xxxx3xxxx4x\n.....xxx5xxxx6xxx\n.....x7xxxx8xxxx9\n.....xxx \n "
|
||||
);
|
||||
assert_eq!(
|
||||
softwrap_text("\t\txxxx1xxx 2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxx9xxx\n"),
|
||||
" xxxx1xxx 2xxx\n.....x3xxxx4xxxx5\n.....xxxx6xxxx7xx\n.....xx8xxxx9xxx \n "
|
||||
);
|
||||
}
|
||||
|
||||
fn overlay_text(text: &str, char_pos: usize, softwrap: bool, overlays: &[Overlay]) -> String {
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
text.into(),
|
||||
&TextFormat::new_test(softwrap),
|
||||
TextAnnotations::default().add_overlay(overlays.into(), None),
|
||||
char_pos,
|
||||
)
|
||||
.0
|
||||
.collect_to_str()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlay() {
|
||||
assert_eq!(
|
||||
overlay_text(
|
||||
"foobar",
|
||||
0,
|
||||
false,
|
||||
&[Overlay::new(0, "X"), Overlay::new(2, "\t")],
|
||||
),
|
||||
"Xo bar "
|
||||
);
|
||||
assert_eq!(
|
||||
overlay_text(
|
||||
&"foo ".repeat(10),
|
||||
0,
|
||||
true,
|
||||
&[
|
||||
Overlay::new(2, "\t"),
|
||||
Overlay::new(5, "\t"),
|
||||
Overlay::new(16, "X"),
|
||||
]
|
||||
),
|
||||
"fo f o foo \n.foo Xoo foo foo \n.foo foo foo "
|
||||
);
|
||||
}
|
||||
|
||||
fn annotate_text(text: &str, softwrap: bool, annotations: &[InlineAnnotation]) -> String {
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
text.into(),
|
||||
&TextFormat::new_test(softwrap),
|
||||
TextAnnotations::default().add_inline_annotations(annotations.into(), None),
|
||||
0,
|
||||
)
|
||||
.0
|
||||
.collect_to_str()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annotation() {
|
||||
assert_eq!(
|
||||
annotate_text("bar", false, &[InlineAnnotation::new(0, "foo")]),
|
||||
"foobar "
|
||||
);
|
||||
assert_eq!(
|
||||
annotate_text(
|
||||
&"foo ".repeat(10),
|
||||
true,
|
||||
&[InlineAnnotation::new(0, "foo ")]
|
||||
),
|
||||
"foo foo foo foo \n.foo foo foo foo \n.foo foo foo "
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn annotation_and_overlay() {
|
||||
assert_eq!(
|
||||
DocumentFormatter::new_at_prev_checkpoint(
|
||||
"bbar".into(),
|
||||
&TextFormat::new_test(false),
|
||||
TextAnnotations::default()
|
||||
.add_inline_annotations(Rc::new([InlineAnnotation::new(0, "fooo")]), None)
|
||||
.add_overlay(Rc::new([Overlay::new(0, "\t")]), None),
|
||||
0,
|
||||
)
|
||||
.0
|
||||
.collect_to_str(),
|
||||
"fooo bar "
|
||||
);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
use std::ops::DerefMut;
|
||||
|
||||
use nucleo::pattern::{Atom, AtomKind, CaseMatching};
|
||||
use nucleo::Config;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
pub struct LazyMutex<T> {
|
||||
inner: Mutex<Option<T>>,
|
||||
init: fn() -> T,
|
||||
}
|
||||
|
||||
impl<T> LazyMutex<T> {
|
||||
pub const fn new(init: fn() -> T) -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(None),
|
||||
init,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lock(&self) -> impl DerefMut<Target = T> + '_ {
|
||||
parking_lot::MutexGuard::map(self.inner.lock(), |val| val.get_or_insert_with(self.init))
|
||||
}
|
||||
}
|
||||
|
||||
pub static MATCHER: LazyMutex<nucleo::Matcher> = LazyMutex::new(nucleo::Matcher::default);
|
||||
|
||||
/// convenience function to easily fuzzy match
|
||||
/// on a (relatively small list of inputs). This is not recommended for building a full tui
|
||||
/// application that can match large numbers of matches as all matching is done on the current
|
||||
/// thread, effectively blocking the UI
|
||||
pub fn fuzzy_match<T: AsRef<str>>(
|
||||
pattern: &str,
|
||||
items: impl IntoIterator<Item = T>,
|
||||
path: bool,
|
||||
) -> Vec<(T, u16)> {
|
||||
let mut matcher = MATCHER.lock();
|
||||
matcher.config = Config::DEFAULT;
|
||||
if path {
|
||||
matcher.config.set_match_paths();
|
||||
}
|
||||
let pattern = Atom::new(pattern, CaseMatching::Smart, AtomKind::Fuzzy, false);
|
||||
pattern.match_list(items, &mut matcher)
|
||||
}
|
@ -1,235 +0,0 @@
|
||||
const SEPARATOR: char = '_';
|
||||
|
||||
/// Increment an integer.
|
||||
///
|
||||
/// Supported bases:
|
||||
/// 2 with prefix 0b
|
||||
/// 8 with prefix 0o
|
||||
/// 10 with no prefix
|
||||
/// 16 with prefix 0x
|
||||
///
|
||||
/// An integer can contain `_` as a separator but may not start or end with a separator.
|
||||
/// Base 10 integers can go negative, but bases 2, 8, and 16 cannot.
|
||||
/// All addition and subtraction is saturating.
|
||||
pub fn increment(selected_text: &str, amount: i64) -> Option<String> {
|
||||
if selected_text.is_empty()
|
||||
|| selected_text.ends_with(SEPARATOR)
|
||||
|| selected_text.starts_with(SEPARATOR)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let radix = if selected_text.starts_with("0x") {
|
||||
16
|
||||
} else if selected_text.starts_with("0o") {
|
||||
8
|
||||
} else if selected_text.starts_with("0b") {
|
||||
2
|
||||
} else {
|
||||
10
|
||||
};
|
||||
|
||||
// Get separator indexes from right to left.
|
||||
let separator_rtl_indexes: Vec<usize> = selected_text
|
||||
.chars()
|
||||
.rev()
|
||||
.enumerate()
|
||||
.filter_map(|(i, c)| if c == SEPARATOR { Some(i) } else { None })
|
||||
.collect();
|
||||
|
||||
let word: String = selected_text.chars().filter(|&c| c != SEPARATOR).collect();
|
||||
|
||||
let mut new_text = if radix == 10 {
|
||||
let number = &word;
|
||||
let value = i128::from_str_radix(number, radix).ok()?;
|
||||
let new_value = value.saturating_add(amount as i128);
|
||||
|
||||
let format_length = match (value.is_negative(), new_value.is_negative()) {
|
||||
(true, false) => number.len() - 1,
|
||||
(false, true) => number.len() + 1,
|
||||
_ => number.len(),
|
||||
} - separator_rtl_indexes.len();
|
||||
|
||||
if number.starts_with('0') || number.starts_with("-0") {
|
||||
format!("{:01$}", new_value, format_length)
|
||||
} else {
|
||||
format!("{}", new_value)
|
||||
}
|
||||
} else {
|
||||
let number = &word[2..];
|
||||
let value = u128::from_str_radix(number, radix).ok()?;
|
||||
let new_value = (value as i128).saturating_add(amount as i128);
|
||||
let new_value = if new_value < 0 { 0 } else { new_value };
|
||||
let format_length = selected_text.len() - 2 - separator_rtl_indexes.len();
|
||||
|
||||
match radix {
|
||||
2 => format!("0b{:01$b}", new_value, format_length),
|
||||
8 => format!("0o{:01$o}", new_value, format_length),
|
||||
16 => {
|
||||
let (lower_count, upper_count): (usize, usize) =
|
||||
number.chars().fold((0, 0), |(lower, upper), c| {
|
||||
(
|
||||
lower + c.is_ascii_lowercase() as usize,
|
||||
upper + c.is_ascii_uppercase() as usize,
|
||||
)
|
||||
});
|
||||
if upper_count > lower_count {
|
||||
format!("0x{:01$X}", new_value, format_length)
|
||||
} else {
|
||||
format!("0x{:01$x}", new_value, format_length)
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("radix not supported: {}", radix),
|
||||
}
|
||||
};
|
||||
|
||||
// Add separators from original number.
|
||||
for &rtl_index in &separator_rtl_indexes {
|
||||
if rtl_index < new_text.len() {
|
||||
let new_index = new_text.len().saturating_sub(rtl_index);
|
||||
if new_index > 0 {
|
||||
new_text.insert(new_index, SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add in additional separators if necessary.
|
||||
if new_text.len() > selected_text.len() && !separator_rtl_indexes.is_empty() {
|
||||
let spacing = match separator_rtl_indexes.as_slice() {
|
||||
[.., b, a] => a - b - 1,
|
||||
_ => separator_rtl_indexes[0],
|
||||
};
|
||||
|
||||
let prefix_length = if radix == 10 { 0 } else { 2 };
|
||||
if let Some(mut index) = new_text.find(SEPARATOR) {
|
||||
while index - prefix_length > spacing {
|
||||
index -= spacing;
|
||||
new_text.insert(index, SEPARATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(new_text)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_decimal_numbers() {
|
||||
let tests = [
|
||||
("100", 1, "101"),
|
||||
("100", -1, "99"),
|
||||
("99", 1, "100"),
|
||||
("100", 1000, "1100"),
|
||||
("100", -1000, "-900"),
|
||||
("-1", 1, "0"),
|
||||
("-1", 2, "1"),
|
||||
("1", -1, "0"),
|
||||
("1", -2, "-1"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
assert_eq!(increment(original, amount).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_hexadecimal_numbers() {
|
||||
let tests = [
|
||||
("0x0100", 1, "0x0101"),
|
||||
("0x0100", -1, "0x00ff"),
|
||||
("0x0001", -1, "0x0000"),
|
||||
("0x0000", -1, "0x0000"),
|
||||
("0xffffffffffffffff", 1, "0x10000000000000000"),
|
||||
("0xffffffffffffffff", 2, "0x10000000000000001"),
|
||||
("0xffffffffffffffff", -1, "0xfffffffffffffffe"),
|
||||
("0xABCDEF1234567890", 1, "0xABCDEF1234567891"),
|
||||
("0xabcdef1234567890", 1, "0xabcdef1234567891"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
assert_eq!(increment(original, amount).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_octal_numbers() {
|
||||
let tests = [
|
||||
("0o0107", 1, "0o0110"),
|
||||
("0o0110", -1, "0o0107"),
|
||||
("0o0001", -1, "0o0000"),
|
||||
("0o7777", 1, "0o10000"),
|
||||
("0o1000", -1, "0o0777"),
|
||||
("0o0107", 10, "0o0121"),
|
||||
("0o0000", -1, "0o0000"),
|
||||
("0o1777777777777777777777", 1, "0o2000000000000000000000"),
|
||||
("0o1777777777777777777777", 2, "0o2000000000000000000001"),
|
||||
("0o1777777777777777777777", -1, "0o1777777777777777777776"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
assert_eq!(increment(original, amount).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_binary_numbers() {
|
||||
let tests = [
|
||||
("0b00000100", 1, "0b00000101"),
|
||||
("0b00000100", -1, "0b00000011"),
|
||||
("0b00000100", 2, "0b00000110"),
|
||||
("0b00000100", -2, "0b00000010"),
|
||||
("0b00000001", -1, "0b00000000"),
|
||||
("0b00111111", 10, "0b01001001"),
|
||||
("0b11111111", 1, "0b100000000"),
|
||||
("0b10000000", -1, "0b01111111"),
|
||||
("0b0000", -1, "0b0000"),
|
||||
(
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
1,
|
||||
"0b10000000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
(
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
2,
|
||||
"0b10000000000000000000000000000000000000000000000000000000000000001",
|
||||
),
|
||||
(
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
-1,
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111110",
|
||||
),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
assert_eq!(increment(original, amount).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_with_separators() {
|
||||
let tests = [
|
||||
("999_999", 1, "1_000_000"),
|
||||
("1_000_000", -1, "999_999"),
|
||||
("-999_999", -1, "-1_000_000"),
|
||||
("0x0000_0000_0001", 0x1_ffff_0000, "0x0001_ffff_0001"),
|
||||
("0x0000_0000", -1, "0x0000_0000"),
|
||||
("0x0000_0000_0000", -1, "0x0000_0000_0000"),
|
||||
("0b01111111_11111111", 1, "0b10000000_00000000"),
|
||||
("0b11111111_11111111", 1, "0b1_00000000_00000000"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
assert_eq!(increment(original, amount).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_leading_and_trailing_separators_arent_a_match() {
|
||||
assert_eq!(increment("9_", 1), None);
|
||||
assert_eq!(increment("_9", 1), None);
|
||||
assert_eq!(increment("_9_", 1), None);
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
mod date_time;
|
||||
mod integer;
|
||||
pub mod date_time;
|
||||
pub mod number;
|
||||
|
||||
pub fn integer(selected_text: &str, amount: i64) -> Option<String> {
|
||||
integer::increment(selected_text, amount)
|
||||
}
|
||||
use crate::{Range, Tendril};
|
||||
|
||||
pub fn date_time(selected_text: &str, amount: i64) -> Option<String> {
|
||||
date_time::increment(selected_text, amount)
|
||||
pub trait Increment {
|
||||
fn increment(&self, amount: i64) -> (Range, Tendril);
|
||||
}
|
||||
|
@ -0,0 +1,507 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ropey::RopeSlice;
|
||||
|
||||
use super::Increment;
|
||||
|
||||
use crate::{
|
||||
textobject::{textobject_word, TextObject},
|
||||
Range, Tendril,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct NumberIncrementor<'a> {
|
||||
value: i64,
|
||||
radix: u32,
|
||||
range: Range,
|
||||
|
||||
text: RopeSlice<'a>,
|
||||
}
|
||||
|
||||
impl<'a> NumberIncrementor<'a> {
|
||||
/// Return information about number under rang if there is one.
|
||||
pub fn from_range(text: RopeSlice, range: Range) -> Option<NumberIncrementor> {
|
||||
// If the cursor is on the minus sign of a number we want to get the word textobject to the
|
||||
// right of it.
|
||||
let range = if range.to() < text.len_chars()
|
||||
&& range.to() - range.from() <= 1
|
||||
&& text.char(range.from()) == '-'
|
||||
{
|
||||
Range::new(range.from() + 1, range.to() + 1)
|
||||
} else {
|
||||
range
|
||||
};
|
||||
|
||||
let range = textobject_word(text, range, TextObject::Inside, 1, false);
|
||||
|
||||
// If there is a minus sign to the left of the word object, we want to include it in the range.
|
||||
let range = if range.from() > 0 && text.char(range.from() - 1) == '-' {
|
||||
range.extend(range.from() - 1, range.from())
|
||||
} else {
|
||||
range
|
||||
};
|
||||
|
||||
let word: String = text
|
||||
.slice(range.from()..range.to())
|
||||
.chars()
|
||||
.filter(|&c| c != '_')
|
||||
.collect();
|
||||
let (radix, prefixed) = if word.starts_with("0x") {
|
||||
(16, true)
|
||||
} else if word.starts_with("0o") {
|
||||
(8, true)
|
||||
} else if word.starts_with("0b") {
|
||||
(2, true)
|
||||
} else {
|
||||
(10, false)
|
||||
};
|
||||
|
||||
let number = if prefixed { &word[2..] } else { &word };
|
||||
|
||||
let value = i128::from_str_radix(number, radix).ok()?;
|
||||
if (value.is_positive() && value.leading_zeros() < 64)
|
||||
|| (value.is_negative() && value.leading_ones() < 64)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let value = value as i64;
|
||||
Some(NumberIncrementor {
|
||||
range,
|
||||
value,
|
||||
radix,
|
||||
text,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Increment for NumberIncrementor<'a> {
|
||||
fn increment(&self, amount: i64) -> (Range, Tendril) {
|
||||
let old_text: Cow<str> = self.text.slice(self.range.from()..self.range.to()).into();
|
||||
let old_length = old_text.len();
|
||||
let new_value = self.value.wrapping_add(amount);
|
||||
|
||||
// Get separator indexes from right to left.
|
||||
let separator_rtl_indexes: Vec<usize> = old_text
|
||||
.chars()
|
||||
.rev()
|
||||
.enumerate()
|
||||
.filter_map(|(i, c)| if c == '_' { Some(i) } else { None })
|
||||
.collect();
|
||||
|
||||
let format_length = if self.radix == 10 {
|
||||
match (self.value.is_negative(), new_value.is_negative()) {
|
||||
(true, false) => old_length - 1,
|
||||
(false, true) => old_length + 1,
|
||||
_ => old_text.len(),
|
||||
}
|
||||
} else {
|
||||
old_text.len() - 2
|
||||
} - separator_rtl_indexes.len();
|
||||
|
||||
let mut new_text = match self.radix {
|
||||
2 => format!("0b{:01$b}", new_value, format_length),
|
||||
8 => format!("0o{:01$o}", new_value, format_length),
|
||||
10 if old_text.starts_with('0') || old_text.starts_with("-0") => {
|
||||
format!("{:01$}", new_value, format_length)
|
||||
}
|
||||
10 => format!("{}", new_value),
|
||||
16 => {
|
||||
let (lower_count, upper_count): (usize, usize) =
|
||||
old_text.chars().skip(2).fold((0, 0), |(lower, upper), c| {
|
||||
(
|
||||
lower + c.is_ascii_lowercase().then(|| 1).unwrap_or(0),
|
||||
upper + c.is_ascii_uppercase().then(|| 1).unwrap_or(0),
|
||||
)
|
||||
});
|
||||
if upper_count > lower_count {
|
||||
format!("0x{:01$X}", new_value, format_length)
|
||||
} else {
|
||||
format!("0x{:01$x}", new_value, format_length)
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("radix not supported: {}", self.radix),
|
||||
};
|
||||
|
||||
// Add separators from original number.
|
||||
for &rtl_index in &separator_rtl_indexes {
|
||||
if rtl_index < new_text.len() {
|
||||
let new_index = new_text.len() - rtl_index;
|
||||
new_text.insert(new_index, '_');
|
||||
}
|
||||
}
|
||||
|
||||
// Add in additional separators if necessary.
|
||||
if new_text.len() > old_length && !separator_rtl_indexes.is_empty() {
|
||||
let spacing = match separator_rtl_indexes.as_slice() {
|
||||
[.., b, a] => a - b - 1,
|
||||
_ => separator_rtl_indexes[0],
|
||||
};
|
||||
|
||||
let prefix_length = if self.radix == 10 { 0 } else { 2 };
|
||||
if let Some(mut index) = new_text.find('_') {
|
||||
while index - prefix_length > spacing {
|
||||
index -= spacing;
|
||||
new_text.insert(index, '_');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(self.range, new_text.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::Rope;
|
||||
|
||||
#[test]
|
||||
fn test_decimal_at_point() {
|
||||
let rope = Rope::from_str("Test text 12345 more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 15),
|
||||
value: 12345,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uppercase_hexadecimal_at_point() {
|
||||
let rope = Rope::from_str("Test text 0x123ABCDEF more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 21),
|
||||
value: 0x123ABCDEF,
|
||||
radix: 16,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lowercase_hexadecimal_at_point() {
|
||||
let rope = Rope::from_str("Test text 0xfa3b4e more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 18),
|
||||
value: 0xfa3b4e,
|
||||
radix: 16,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_octal_at_point() {
|
||||
let rope = Rope::from_str("Test text 0o1074312 more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 19),
|
||||
value: 0o1074312,
|
||||
radix: 8,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_binary_at_point() {
|
||||
let rope = Rope::from_str("Test text 0b10111010010101 more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 26),
|
||||
value: 0b10111010010101,
|
||||
radix: 2,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_decimal_at_point() {
|
||||
let rope = Rope::from_str("Test text -54321 more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 16),
|
||||
value: -54321,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decimal_with_leading_zeroes_at_point() {
|
||||
let rope = Rope::from_str("Test text 000045326 more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 19),
|
||||
value: 45326,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_decimal_cursor_on_minus_sign() {
|
||||
let rope = Rope::from_str("Test text -54321 more text.");
|
||||
let range = Range::point(10);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(10, 16),
|
||||
value: -54321,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_under_range_start_of_rope() {
|
||||
let rope = Rope::from_str("100");
|
||||
let range = Range::point(0);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(0, 3),
|
||||
value: 100,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_under_range_end_of_rope() {
|
||||
let rope = Rope::from_str("100");
|
||||
let range = Range::point(2);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(0, 3),
|
||||
value: 100,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_surrounded_by_punctuation() {
|
||||
let rope = Rope::from_str(",100;");
|
||||
let range = Range::point(1);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range),
|
||||
Some(NumberIncrementor {
|
||||
range: Range::new(1, 4),
|
||||
value: 100,
|
||||
radix: 10,
|
||||
text: rope.slice(..),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_a_number_point() {
|
||||
let rope = Rope::from_str("Test text 45326 more text.");
|
||||
let range = Range::point(6);
|
||||
assert_eq!(NumberIncrementor::from_range(rope.slice(..), range), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_too_large_at_point() {
|
||||
let rope = Rope::from_str("Test text 0xFFFFFFFFFFFFFFFFF more text.");
|
||||
let range = Range::point(12);
|
||||
assert_eq!(NumberIncrementor::from_range(rope.slice(..), range), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_cursor_one_right_of_number() {
|
||||
let rope = Rope::from_str("100 ");
|
||||
let range = Range::point(3);
|
||||
assert_eq!(NumberIncrementor::from_range(rope.slice(..), range), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_cursor_one_left_of_number() {
|
||||
let rope = Rope::from_str(" 100");
|
||||
let range = Range::point(0);
|
||||
assert_eq!(NumberIncrementor::from_range(rope.slice(..), range), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_decimal_numbers() {
|
||||
let tests = [
|
||||
("100", 1, "101"),
|
||||
("100", -1, "99"),
|
||||
("99", 1, "100"),
|
||||
("100", 1000, "1100"),
|
||||
("100", -1000, "-900"),
|
||||
("-1", 1, "0"),
|
||||
("-1", 2, "1"),
|
||||
("1", -1, "0"),
|
||||
("1", -2, "-1"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
let rope = Rope::from_str(original);
|
||||
let range = Range::point(0);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range)
|
||||
.unwrap()
|
||||
.increment(amount)
|
||||
.1,
|
||||
Tendril::from(expected)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_hexadecimal_numbers() {
|
||||
let tests = [
|
||||
("0x0100", 1, "0x0101"),
|
||||
("0x0100", -1, "0x00ff"),
|
||||
("0x0001", -1, "0x0000"),
|
||||
("0x0000", -1, "0xffffffffffffffff"),
|
||||
("0xffffffffffffffff", 1, "0x0000000000000000"),
|
||||
("0xffffffffffffffff", 2, "0x0000000000000001"),
|
||||
("0xffffffffffffffff", -1, "0xfffffffffffffffe"),
|
||||
("0xABCDEF1234567890", 1, "0xABCDEF1234567891"),
|
||||
("0xabcdef1234567890", 1, "0xabcdef1234567891"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
let rope = Rope::from_str(original);
|
||||
let range = Range::point(0);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range)
|
||||
.unwrap()
|
||||
.increment(amount)
|
||||
.1,
|
||||
Tendril::from(expected)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_octal_numbers() {
|
||||
let tests = [
|
||||
("0o0107", 1, "0o0110"),
|
||||
("0o0110", -1, "0o0107"),
|
||||
("0o0001", -1, "0o0000"),
|
||||
("0o7777", 1, "0o10000"),
|
||||
("0o1000", -1, "0o0777"),
|
||||
("0o0107", 10, "0o0121"),
|
||||
("0o0000", -1, "0o1777777777777777777777"),
|
||||
("0o1777777777777777777777", 1, "0o0000000000000000000000"),
|
||||
("0o1777777777777777777777", 2, "0o0000000000000000000001"),
|
||||
("0o1777777777777777777777", -1, "0o1777777777777777777776"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
let rope = Rope::from_str(original);
|
||||
let range = Range::point(0);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range)
|
||||
.unwrap()
|
||||
.increment(amount)
|
||||
.1,
|
||||
Tendril::from(expected)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_basic_binary_numbers() {
|
||||
let tests = [
|
||||
("0b00000100", 1, "0b00000101"),
|
||||
("0b00000100", -1, "0b00000011"),
|
||||
("0b00000100", 2, "0b00000110"),
|
||||
("0b00000100", -2, "0b00000010"),
|
||||
("0b00000001", -1, "0b00000000"),
|
||||
("0b00111111", 10, "0b01001001"),
|
||||
("0b11111111", 1, "0b100000000"),
|
||||
("0b10000000", -1, "0b01111111"),
|
||||
(
|
||||
"0b0000",
|
||||
-1,
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
),
|
||||
(
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
1,
|
||||
"0b0000000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
(
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
2,
|
||||
"0b0000000000000000000000000000000000000000000000000000000000000001",
|
||||
),
|
||||
(
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
-1,
|
||||
"0b1111111111111111111111111111111111111111111111111111111111111110",
|
||||
),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
let rope = Rope::from_str(original);
|
||||
let range = Range::point(0);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range)
|
||||
.unwrap()
|
||||
.increment(amount)
|
||||
.1,
|
||||
Tendril::from(expected)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increment_with_separators() {
|
||||
let tests = [
|
||||
("999_999", 1, "1_000_000"),
|
||||
("1_000_000", -1, "999_999"),
|
||||
("-999_999", -1, "-1_000_000"),
|
||||
("0x0000_0000_0001", 0x1_ffff_0000, "0x0001_ffff_0001"),
|
||||
("0x0000_0000_0001", 0x1_ffff_0000, "0x0001_ffff_0001"),
|
||||
("0x0000_0000_0001", 0x1_ffff_0000, "0x0001_ffff_0001"),
|
||||
("0x0000_0000", -1, "0xffff_ffff_ffff_ffff"),
|
||||
("0x0000_0000_0000", -1, "0xffff_ffff_ffff_ffff"),
|
||||
("0b01111111_11111111", 1, "0b10000000_00000000"),
|
||||
("0b11111111_11111111", 1, "0b1_00000000_00000000"),
|
||||
];
|
||||
|
||||
for (original, amount, expected) in tests {
|
||||
let rope = Rope::from_str(original);
|
||||
let range = Range::point(0);
|
||||
assert_eq!(
|
||||
NumberIncrementor::from_range(rope.slice(..), range)
|
||||
.unwrap()
|
||||
.increment(amount)
|
||||
.1,
|
||||
Tendril::from(expected)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Register {
|
||||
name: char,
|
||||
values: Vec<String>,
|
||||
}
|
||||
|
||||
impl Register {
|
||||
pub const fn new(name: char) -> Self {
|
||||
Self {
|
||||
name,
|
||||
values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_values(name: char, values: Vec<String>) -> Self {
|
||||
if name == '_' {
|
||||
Self::new(name)
|
||||
} else {
|
||||
Self { name, values }
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn name(&self) -> char {
|
||||
self.name
|
||||
}
|
||||
|
||||
pub fn read(&self) -> &[String] {
|
||||
&self.values
|
||||
}
|
||||
|
||||
pub fn write(&mut self, values: Vec<String>) {
|
||||
if self.name != '_' {
|
||||
self.values = values;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, value: String) {
|
||||
if self.name != '_' {
|
||||
self.values.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Currently just wraps a `HashMap` of `Register`s
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Registers {
|
||||
inner: HashMap<char, Register>,
|
||||
}
|
||||
|
||||
impl Registers {
|
||||
pub fn get(&self, name: char) -> Option<&Register> {
|
||||
self.inner.get(&name)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, name: char) -> &mut Register {
|
||||
self.inner
|
||||
.entry(name)
|
||||
.or_insert_with(|| Register::new(name))
|
||||
}
|
||||
|
||||
pub fn write(&mut self, name: char, values: Vec<String>) {
|
||||
self.inner
|
||||
.insert(name, Register::new_with_values(name, values));
|
||||
}
|
||||
|
||||
pub fn read(&self, name: char) -> Option<&[String]> {
|
||||
self.get(name).map(|reg| reg.read())
|
||||
}
|
||||
|
||||
pub fn first(&self, name: char) -> Option<&String> {
|
||||
self.read(name).and_then(|entries| entries.first())
|
||||
}
|
||||
|
||||
pub fn last(&self, name: char) -> Option<&String> {
|
||||
self.read(name).and_then(|entries| entries.last())
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &HashMap<char, Register> {
|
||||
&self.inner
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
use std::io;
|
||||
|
||||
use ropey::iter::Chunks;
|
||||
use ropey::RopeSlice;
|
||||
|
||||
pub struct RopeReader<'a> {
|
||||
current_chunk: &'a [u8],
|
||||
chunks: Chunks<'a>,
|
||||
}
|
||||
|
||||
impl<'a> RopeReader<'a> {
|
||||
pub fn new(rope: RopeSlice<'a>) -> RopeReader<'a> {
|
||||
RopeReader {
|
||||
current_chunk: &[],
|
||||
chunks: rope.chunks(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Read for RopeReader<'_> {
|
||||
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
|
||||
let buf_len = buf.len();
|
||||
loop {
|
||||
let read_bytes = self.current_chunk.read(buf)?;
|
||||
buf = &mut buf[read_bytes..];
|
||||
if buf.is_empty() {
|
||||
return Ok(buf_len);
|
||||
}
|
||||
|
||||
if let Some(next_chunk) = self.chunks.next() {
|
||||
self.current_chunk = next_chunk.as_bytes();
|
||||
} else {
|
||||
return Ok(buf_len - buf.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
use crate::{Rope, Selection};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct State {
|
||||
pub doc: Rope,
|
||||
pub selection: Selection,
|
||||
}
|
||||
|
||||
impl State {
|
||||
#[must_use]
|
||||
pub fn new(doc: Rope) -> Self {
|
||||
Self {
|
||||
doc,
|
||||
selection: Selection::point(0),
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,271 +0,0 @@
|
||||
use std::cell::Cell;
|
||||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::syntax::Highlight;
|
||||
use crate::Tendril;
|
||||
|
||||
/// An inline annotation is continuous text shown
|
||||
/// on the screen before the grapheme that starts at
|
||||
/// `char_idx`
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InlineAnnotation {
|
||||
pub text: Tendril,
|
||||
pub char_idx: usize,
|
||||
}
|
||||
|
||||
impl InlineAnnotation {
|
||||
pub fn new(char_idx: usize, text: impl Into<Tendril>) -> Self {
|
||||
Self {
|
||||
char_idx,
|
||||
text: text.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a **single Grapheme** that is part of the document
|
||||
/// that start at `char_idx` that will be replaced with
|
||||
/// a different `grapheme`.
|
||||
/// If `grapheme` contains multiple graphemes the text
|
||||
/// will render incorrectly.
|
||||
/// If you want to overlay multiple graphemes simply
|
||||
/// use multiple `Overlays`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The following examples are valid overlays for the following text:
|
||||
///
|
||||
/// `aX͎̊͢͜͝͡bc`
|
||||
///
|
||||
/// ```
|
||||
/// use helix_core::text_annotations::Overlay;
|
||||
///
|
||||
/// // replaces a
|
||||
/// Overlay::new(0, "X");
|
||||
///
|
||||
/// // replaces X͎̊͢͜͝͡
|
||||
/// Overlay::new(1, "\t");
|
||||
///
|
||||
/// // replaces b
|
||||
/// Overlay::new(6, "X̢̢̟͖̲͌̋̇͑͝");
|
||||
/// ```
|
||||
///
|
||||
/// The following examples are invalid uses
|
||||
///
|
||||
/// ```
|
||||
/// use helix_core::text_annotations::Overlay;
|
||||
///
|
||||
/// // overlay is not aligned at grapheme boundary
|
||||
/// Overlay::new(3, "x");
|
||||
///
|
||||
/// // overlay contains multiple graphemes
|
||||
/// Overlay::new(0, "xy");
|
||||
/// ```
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Overlay {
|
||||
pub char_idx: usize,
|
||||
pub grapheme: Tendril,
|
||||
}
|
||||
|
||||
impl Overlay {
|
||||
pub fn new(char_idx: usize, grapheme: impl Into<Tendril>) -> Self {
|
||||
Self {
|
||||
char_idx,
|
||||
grapheme: grapheme.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Line annotations allow for virtual text between normal
|
||||
/// text lines. They cause `height` empty lines to be inserted
|
||||
/// below the document line that contains `anchor_char_idx`.
|
||||
///
|
||||
/// These lines can be filled with text in the rendering code
|
||||
/// as their contents have no effect beyond visual appearance.
|
||||
///
|
||||
/// To insert a line after a document line simply set
|
||||
/// `anchor_char_idx` to `doc.line_to_char(line_idx)`
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LineAnnotation {
|
||||
pub anchor_char_idx: usize,
|
||||
pub height: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Layer<A, M> {
|
||||
annotations: Rc<[A]>,
|
||||
current_index: Cell<usize>,
|
||||
metadata: M,
|
||||
}
|
||||
|
||||
impl<A, M: Clone> Clone for Layer<A, M> {
|
||||
fn clone(&self) -> Self {
|
||||
Layer {
|
||||
annotations: self.annotations.clone(),
|
||||
current_index: self.current_index.clone(),
|
||||
metadata: self.metadata.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, M> Layer<A, M> {
|
||||
pub fn reset_pos(&self, char_idx: usize, get_char_idx: impl Fn(&A) -> usize) {
|
||||
let new_index = self
|
||||
.annotations
|
||||
.partition_point(|annot| get_char_idx(annot) < char_idx);
|
||||
self.current_index.set(new_index);
|
||||
}
|
||||
|
||||
pub fn consume(&self, char_idx: usize, get_char_idx: impl Fn(&A) -> usize) -> Option<&A> {
|
||||
let annot = self.annotations.get(self.current_index.get())?;
|
||||
debug_assert!(get_char_idx(annot) >= char_idx);
|
||||
if get_char_idx(annot) == char_idx {
|
||||
self.current_index.set(self.current_index.get() + 1);
|
||||
Some(annot)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, M> From<(Rc<[A]>, M)> for Layer<A, M> {
|
||||
fn from((annotations, metadata): (Rc<[A]>, M)) -> Layer<A, M> {
|
||||
Layer {
|
||||
annotations,
|
||||
current_index: Cell::new(0),
|
||||
metadata,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn reset_pos<A, M>(layers: &[Layer<A, M>], pos: usize, get_pos: impl Fn(&A) -> usize) {
|
||||
for layer in layers {
|
||||
layer.reset_pos(pos, &get_pos)
|
||||
}
|
||||
}
|
||||
|
||||
/// Annotations that change that is displayed when the document is render.
|
||||
/// Also commonly called virtual text.
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct TextAnnotations {
|
||||
inline_annotations: Vec<Layer<InlineAnnotation, Option<Highlight>>>,
|
||||
overlays: Vec<Layer<Overlay, Option<Highlight>>>,
|
||||
line_annotations: Vec<Layer<LineAnnotation, ()>>,
|
||||
}
|
||||
|
||||
impl TextAnnotations {
|
||||
/// Prepare the TextAnnotations for iteration starting at char_idx
|
||||
pub fn reset_pos(&self, char_idx: usize) {
|
||||
reset_pos(&self.inline_annotations, char_idx, |annot| annot.char_idx);
|
||||
reset_pos(&self.overlays, char_idx, |annot| annot.char_idx);
|
||||
reset_pos(&self.line_annotations, char_idx, |annot| {
|
||||
annot.anchor_char_idx
|
||||
});
|
||||
}
|
||||
|
||||
pub fn collect_overlay_highlights(
|
||||
&self,
|
||||
char_range: Range<usize>,
|
||||
) -> Vec<(usize, Range<usize>)> {
|
||||
let mut highlights = Vec::new();
|
||||
self.reset_pos(char_range.start);
|
||||
for char_idx in char_range {
|
||||
if let Some((_, Some(highlight))) = self.overlay_at(char_idx) {
|
||||
// we don't know the number of chars the original grapheme takes
|
||||
// however it doesn't matter as highlight boundaries are automatically
|
||||
// aligned to grapheme boundaries in the rendering code
|
||||
highlights.push((highlight.0, char_idx..char_idx + 1))
|
||||
}
|
||||
}
|
||||
|
||||
highlights
|
||||
}
|
||||
|
||||
/// Add new inline annotations.
|
||||
///
|
||||
/// The annotations grapheme will be rendered with `highlight`
|
||||
/// patched on top of `ui.text`.
|
||||
///
|
||||
/// The annotations **must be sorted** by their `char_idx`.
|
||||
/// Multiple annotations with the same `char_idx` are allowed,
|
||||
/// they will be display in the order that they are present in the layer.
|
||||
///
|
||||
/// If multiple layers contain annotations at the same position
|
||||
/// the annotations that belong to the layers added first will be shown first.
|
||||
pub fn add_inline_annotations(
|
||||
&mut self,
|
||||
layer: Rc<[InlineAnnotation]>,
|
||||
highlight: Option<Highlight>,
|
||||
) -> &mut Self {
|
||||
self.inline_annotations.push((layer, highlight).into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add new grapheme overlays.
|
||||
///
|
||||
/// The overlaid grapheme will be rendered with `highlight`
|
||||
/// patched on top of `ui.text`.
|
||||
///
|
||||
/// The overlays **must be sorted** by their `char_idx`.
|
||||
/// Multiple overlays with the same `char_idx` **are allowed**.
|
||||
///
|
||||
/// If multiple layers contain overlay at the same position
|
||||
/// the overlay from the layer added last will be show.
|
||||
pub fn add_overlay(&mut self, layer: Rc<[Overlay]>, highlight: Option<Highlight>) -> &mut Self {
|
||||
self.overlays.push((layer, highlight).into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add new annotation lines.
|
||||
///
|
||||
/// The line annotations **must be sorted** by their `char_idx`.
|
||||
/// Multiple line annotations with the same `char_idx` **are not allowed**.
|
||||
pub fn add_line_annotation(&mut self, layer: Rc<[LineAnnotation]>) -> &mut Self {
|
||||
self.line_annotations.push((layer, ()).into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Removes all line annotations, useful for vertical motions
|
||||
/// so that virtual text lines are automatically skipped.
|
||||
pub fn clear_line_annotations(&mut self) {
|
||||
self.line_annotations.clear();
|
||||
}
|
||||
|
||||
pub(crate) fn next_inline_annotation_at(
|
||||
&self,
|
||||
char_idx: usize,
|
||||
) -> Option<(&InlineAnnotation, Option<Highlight>)> {
|
||||
self.inline_annotations.iter().find_map(|layer| {
|
||||
let annotation = layer.consume(char_idx, |annot| annot.char_idx)?;
|
||||
Some((annotation, layer.metadata))
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn overlay_at(&self, char_idx: usize) -> Option<(&Overlay, Option<Highlight>)> {
|
||||
let mut overlay = None;
|
||||
for layer in &self.overlays {
|
||||
while let Some(new_overlay) = layer.consume(char_idx, |annot| annot.char_idx) {
|
||||
overlay = Some((new_overlay, layer.metadata));
|
||||
}
|
||||
}
|
||||
overlay
|
||||
}
|
||||
|
||||
pub(crate) fn annotation_lines_at(&self, char_idx: usize) -> usize {
|
||||
self.line_annotations
|
||||
.iter()
|
||||
.map(|layer| {
|
||||
let mut lines = 0;
|
||||
while let Some(annot) = layer.annotations.get(layer.current_index.get()) {
|
||||
if annot.anchor_char_idx == char_idx {
|
||||
layer.current_index.set(layer.current_index.get() + 1);
|
||||
lines += annot.height
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
lines
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
std::vector<std::string>
|
||||
fn_with_many_parameters(int parm1, long parm2, float parm3, double parm4,
|
||||
char* parm5, bool parm6);
|
||||
|
||||
std::vector<std::string>
|
||||
fn_with_many_parameters(int parm1, long parm2, float parm3, double parm4,
|
||||
char* parm5, bool parm6) {
|
||||
auto lambda = []() {
|
||||
return 0;
|
||||
};
|
||||
auto lambda_with_a_really_long_name_that_uses_a_whole_line
|
||||
= [](int some_more_aligned_parameters,
|
||||
std::string parm2) {
|
||||
do_smth();
|
||||
};
|
||||
if (brace_on_same_line) {
|
||||
do_smth();
|
||||
} else if (brace_on_next_line)
|
||||
{
|
||||
do_smth();
|
||||
} else if (another_condition) {
|
||||
do_smth();
|
||||
}
|
||||
else {
|
||||
do_smth();
|
||||
}
|
||||
if (inline_if_statement)
|
||||
do_smth();
|
||||
if (another_inline_if_statement)
|
||||
return [](int parm1, char* parm2) {
|
||||
this_is_a_really_pointless_lambda();
|
||||
};
|
||||
|
||||
switch (var) {
|
||||
case true:
|
||||
return -1;
|
||||
case false:
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass : public MyBaseClass {
|
||||
public:
|
||||
MyClass();
|
||||
void public_fn();
|
||||
private:
|
||||
super_secret_private_fn();
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
[package]
|
||||
name = "helix-event"
|
||||
version = "0.6.0"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot"] }
|
||||
parking_lot = { version = "0.12", features = ["send_guard"] }
|
@ -1,8 +0,0 @@
|
||||
//! `helix-event` contains systems that allow (often async) communication between
|
||||
//! different editor components without strongly coupling them. Currently this
|
||||
//! crate only contains some smaller facilities but the intend is to add more
|
||||
//! functionality in the future ( like a generic hook system)
|
||||
|
||||
pub use redraw::{lock_frame, redraw_requested, request_redraw, start_frame, RenderLockGuard};
|
||||
|
||||
mod redraw;
|
@ -1,49 +0,0 @@
|
||||
//! Signals that control when/if the editor redraws
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use tokio::sync::Notify;
|
||||
|
||||
/// A `Notify` instance that can be used to (asynchronously) request
|
||||
/// the editor the render a new frame.
|
||||
static REDRAW_NOTIFY: Notify = Notify::const_new();
|
||||
|
||||
/// A `RwLock` that prevents the next frame from being
|
||||
/// drawn until an exclusive (write) lock can be acquired.
|
||||
/// This allows asynchsonous tasks to acquire `non-exclusive`
|
||||
/// locks (read) to prevent the next frame from being drawn
|
||||
/// until a certain computation has finished.
|
||||
static RENDER_LOCK: RwLock<()> = RwLock::new(());
|
||||
|
||||
pub type RenderLockGuard = RwLockReadGuard<'static, ()>;
|
||||
|
||||
/// Requests that the editor is redrawn. The redraws are debounced (currently to
|
||||
/// 30FPS) so this can be called many times without causing a ton of frames to
|
||||
/// be rendered.
|
||||
pub fn request_redraw() {
|
||||
REDRAW_NOTIFY.notify_one();
|
||||
}
|
||||
|
||||
/// Returns a future that will yield once a redraw has been asynchronously
|
||||
/// requested using [`request_redraw`].
|
||||
pub fn redraw_requested() -> impl Future<Output = ()> {
|
||||
REDRAW_NOTIFY.notified()
|
||||
}
|
||||
|
||||
/// Wait until all locks acquired with [`lock_frame`] have been released.
|
||||
/// This function is called before rendering and is intended to allow the frame
|
||||
/// to wait for async computations that should be included in the current frame.
|
||||
pub fn start_frame() {
|
||||
drop(RENDER_LOCK.write());
|
||||
// exhaust any leftover redraw notifications
|
||||
let notify = REDRAW_NOTIFY.notified();
|
||||
tokio::pin!(notify);
|
||||
notify.enable();
|
||||
}
|
||||
|
||||
/// Acquires the render lock which will prevent the next frame from being drawn
|
||||
/// until the returned guard is dropped.
|
||||
pub fn lock_frame() -> RenderLockGuard {
|
||||
RENDER_LOCK.read()
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue