From 3918bbff9323cced0fd42584b0dc5ca987329c3a Mon Sep 17 00:00:00 2001 From: candle Date: Wed, 9 Jul 2025 17:30:03 -0400 Subject: [PATCH] chars index properly now, added readme --- .gitignore | 1 + LICENSE-MIT | 25 ++++++++++++ README.md | 75 ++++++++++++++++++++++++++++++++++ src/ui/central_panel/editor.rs | 8 +++- 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 LICENSE-MIT create mode 100644 README.md diff --git a/.gitignore b/.gitignore index f6d65e3..4f2f988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.c* Cargo.lock /target perf.* diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..f29028a --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) Filip Bicki + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..046e00e --- /dev/null +++ b/README.md @@ -0,0 +1,75 @@ +# ced - candle's Editor + +There is a disturbing lack of simple GUI text editors available on Linux natively. The world of TUI editors is flourishing, but regular people don't 'yank to system register' when they want to move text from one file to another. In the world of GUI text editors you have a few options, all with their own caveats:\ +`gedit` -> Good for the GNOME Desktop, but uses GTK-4.0 so it stands out anywhere else.\ +`Kate` -> If you're not on KDE already, it comes with tons of overhead (52 packages on Arch Linux for an application to write text).\ +`Emacs` -> Requires a degree in understanding its documentation. + +(c)andle's (Ed)itor aims to be a single ~~hopefully small~~ binary for that one purpose. +## Features + +* Sane text editing with standard keybindings (`Ctrl+A`, `Ctrl+C`, etc.). +* Opens with a blank slate for quick typing, remember Notepad? +* Separate UI zoom that doesn't affect font size (`Ctrl+Shift` + `+`/`-`). +* Ricers rejoice, your `pywal` colors will be used! +* Weirdly smooth typing experience. + +## Build and Install +##### Requirements +`git`, `rust`/`rustup`/`cargo` +##### Arch Linux +`sudo pacman -S git rust` +##### Ubuntu/Debian +`sudo apt install git rust` + +#### Install +```bash +git clone https://code.lampnet.io/candle/ced +cd ced && cargo build --release +sudo mv target/release/ced /usr/local/bin/ +sudo install -Dm644 ced.desktop /usr/share/applications/ced.desktop +``` + +`ced` should now appear as 'Text Editor' in your application launcher. You can remove the cloned directory at this point. + +## Configuration + +`ced` will look for, and create if needed, a configuration file at: `$XDG_CONFIG_HOME/ced/config.toml`. + +Here is an example `config.toml`: + +```toml +auto_hide_toolbar = false +show_line_numbers = false +word_wrap = false +theme = "System" +line_side = false +font_family = "Monospace" +font_size = 16.0 +``` + +### Options + +| Option | Default | Description | +|--------|---------|-------------| +| `auto_hide_toolbar` | `false` | If `true`, the menu bar at the top will be hidden. Move your mouse to the top of the window to reveal it. | +| `show_line_numbers` | `false` | If `true`, line numbers will be displayed on the side specified by `line_side`. | +| `line_side` | `false` | If `false`, line numbers are on the left. If `true`, they are on the right. | +| `word_wrap` | `false` | If `true`, lines will wrap when they reach the edge of the window. | +| `font_family` | `"Proportional"` | The font family used for the editor text. | +| `font_size` | `14.0` | `8.0-32.0` The font size for text editing. | +| `theme` | `"System"` | The color scheme for the application. Options: `"System"` (attempts to use colors from `$XDG_CACHE_HOME/wal/colors` if present, otherwise uses system's light/dark mode preference), `"Light"`, or `"Dark"` (manually specify a theme). | + +## Future Plans +In order of importance. +| Feature | Info | +| ------- | ---- | +| **Find/Replace:** | In progress. | +| **State/Cache:** | A toggleable option to keep an application state and prevent "Quit without saving" warnings. | +| **Syntax Highlighting/LSP:** | Looking at allowing you to use/attach your own tools for this. | +| **Choose Font** | More than just Monospace/Proportional. | +| **Vim Mode:** | It's in-escapable. | +| **CLI Mode:** | 💀 | +| **IDE MODE:** | 🤡 | + +I use [Helix](https://helix-editor.com/), btw. diff --git a/src/ui/central_panel/editor.rs b/src/ui/central_panel/editor.rs index a014200..e060a15 100644 --- a/src/ui/central_panel/editor.rs +++ b/src/ui/central_panel/editor.rs @@ -109,8 +109,12 @@ pub(super) fn editor_view( let cursor_pos = cursor_range.primary.index; let content = &active_tab.content; - let text_up_to_cursor = &content[..cursor_pos.min(content.len())]; - let cursor_line = text_up_to_cursor.chars().filter(|&c| c == '\n').count(); + // Count newlines up to cursor position using char_indices to avoid char boundary issues + let cursor_line = content + .char_indices() + .take_while(|(byte_pos, _)| *byte_pos < cursor_pos) + .filter(|(_, ch)| *ch == '\n') + .count(); let font_id = ui .style()