Skip to content

Commit 68925d2

Browse files
authored
Merge pull request #175 from curlpipe/0.6.9
0.6.9
2 parents 610eab2 + 85f2c5e commit 68925d2

26 files changed

+709
-155
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exclude = ["cactus"]
77

88
[package]
99
name = "ox"
10-
version = "0.6.8"
10+
version = "0.6.9"
1111
edition = "2021"
1212
authors = ["Curlpipe <[email protected]>"]
1313
description = "A Rust powered text editor."

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Heading -->
1+
<!-- Heading -->
22
<br />
33
<p align="center">
44
<a href="https://github.com/curlpipe/ox/">
@@ -8,11 +8,11 @@
88
<h1 align="center" style="font-size: 50px;">Ox editor</h1>
99

1010
<p align="center" style="font-size: 20px;">
11-
Ox is a code editor that runs in your terminal.
11+
The simple but flexible text editor
1212
<br><br>
1313
<div align="center" style="display:inline;">
14-
<img src="https://i.postimg.cc/nrs9jksB/image.png" width="49%">
15-
<img src="https://i.postimg.cc/KcQ0nv1Y/image.png" width="49%">
14+
<img src="https://i.postimg.cc/zXB5y0r3/ox-blank.gif" width="49%">
15+
<img src="https://i.postimg.cc/pVkRV33g/ox-code.gif" width="49%">
1616
</div>
1717
<br>
1818
</p>
@@ -28,7 +28,7 @@ Ox is an independent text editor that can be used to write everything from text
2828
If you're looking for a text editor that...
2929
1. :feather: Is lightweight and efficient
3030
2. :wrench: Can be configured to your heart's content
31-
3. :package: Has features out of the box, including
31+
3. :package: Has features out of the box, including
3232
- syntax highlighting
3333
- undo and redo
3434
- search and replace
@@ -40,22 +40,22 @@ If you're looking for a text editor that...
4040

4141
It runs in your terminal as a text-user-interface, just like vim, nano and micro, however, it is not based on any existing editors and has been built from the ground up.
4242

43-
It is mainly used on linux systems, but macOS and Windows users (via WSL) are free to give it a go.
43+
It is mainly designed on linux systems, but macOS and Windows users (via WSL) are free to give it a go. Work is currently underway to get it working perfectly on all systems.
4444

4545
## Selling Points
4646

4747
### Lightweight and Efficient
4848

49-
- :feather: Ox is lightweight, with the precompiled binary taking up roughly 4mb in storage space.
49+
- :feather: Ox is lightweight, with the precompiled binary taking up roughly 5mb in storage space.
5050
- :knot: It uses a `rope` data structure which allows incremental editing, file reading and file writing, which will speed up performance, particularly on huge files.
51-
- :crab: It was built in Rust, which is a quick lower level language that has a strong reputation in the performance department.
51+
- :crab: It was built in Rust, which is a quick lower-level language that has a strong reputation in the performance department.
5252

5353
### Strong configurability
5454

5555
- :electric_plug: Plug-In system where you can write your own plug-ins or integrate other people's
5656
- :wrench: A wide number of options for configuration with everything from colours to the status line to syntax highlighting being open to customisation
5757
- :moon: Ox uses Lua as a configuration language for familiarity when scripting and configuring
58-
- 🤝 A configuration assistant to quickly get Ox set up for you from the get-go
58+
- :handshake: A configuration assistant to quickly get Ox set up for you from the get-go
5959

6060
### Out of the box features
6161

@@ -161,6 +161,8 @@ ox
161161

162162
This will open up an empty document.
163163

164+
However, if you've just downloaded Ox, the configuration assistant will automatically start up and help you configure the editor initially.
165+
164166
If you wish to open a file straight from the command line, you can run
165167
```sh
166168
ox /path/to/file
@@ -228,6 +230,8 @@ We've covered most keyboard shortcuts, but there are some other features you mig
228230

229231
Ox features a configuration system that allows the editor to be modified and personalised.
230232

233+
By default, you will be greeted by a configuration assistant when first starting Ox, when no configuration file is in place. This will help you generate a configuration file.
234+
231235
By default, Ox will look for a file here: `$XDG_CONFIG_HOME/.oxrc` or `~/.oxrc`.
232236

233237
On Windows, Ox will try to look here `C:/Users/user/ox/.oxrc` (where `user` is the user name of your account)
@@ -236,18 +240,16 @@ Ox's configuration language is [Lua](https://lua.org).
236240

237241
For reference, there is a default config in the `config` folder in the repository. You can either download it and place it in the default config directory or create your own using the example ones as a reference.
238242

239-
If you don't have a config file or don't want to mess around with it, don't worry, Ox has default settings it will use.
240-
241243
## Documentation
242244

243245
If you've been through the quick start guide above, but are looking for more detail, you can find in-depth documentation on the [wiki page](https://github.com/curlpipe/ox/wiki/)
244246

245-
This will take you step-by-step in great detail through 5 different stages:
247+
This will take you step-by-step in great detail through 6 different stages:
246248

247249
1. **Installation** - advice and how-tos on installation
248-
2. **Starting** - using the command line interface
249-
3. **Using** - editing a document and controlling the editor
250-
4. **Configuring** - writing plug-ins, changing the layout, adding to and changing the syntax highlighting
250+
2. **Configuring** - changing the layout, adding to and changing the syntax highlighting
251+
3. **General Editing** - editing a document and controlling the editor
252+
4. **Command Line** - using the command line interface
251253
5. **Plugins** - installing or uninstalling community plug-ins and writing or distributing your own plug-ins
252254
6. **Roadmap** - planned features
253255

config/.oxrc

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ event_mapping = {
4949
["pagedown"] = function()
5050
editor:move_page_down()
5151
end,
52+
["esc"] = function()
53+
editor:cancel_selection()
54+
end,
55+
["alt_v"] = function()
56+
editor:cursor_to_viewport()
57+
end,
5258
["ctrl_g"] = function()
5359
local line = editor:prompt("Go to line")
5460
editor:move_to(0, tonumber(line))
@@ -116,30 +122,54 @@ event_mapping = {
116122
editor:open_command_line()
117123
end,
118124
["alt_up"] = function()
119-
-- current line information
120-
local line = editor:get_line()
121125
local cursor = editor.cursor
122-
-- insert a new line
123-
editor:insert_line_at(line, cursor.y - 1)
124-
-- delete old copy and reposition cursor
125-
editor:remove_line_at(cursor.y + 1)
126-
-- restore cursor position
127-
editor:move_to(cursor.x, cursor.y - 1)
128-
-- correct indentation level
129-
autoindent:fix_indent()
126+
local select = editor.selection
127+
local single = select.x == cursor.x and select.y == cursor.y
128+
if single then
129+
-- move single line
130+
editor:move_line_up()
131+
autoindent:fix_indent()
132+
else
133+
-- move an entire selection
134+
if cursor.y > select.y then
135+
for line = select.y, cursor.y do
136+
editor:move_to(cursor.x, line)
137+
editor:move_line_up()
138+
end
139+
else
140+
for line = cursor.y, select.y do
141+
editor:move_to(cursor.x, line)
142+
editor:move_line_up()
143+
end
144+
end
145+
editor:move_to(cursor.x, cursor.y - 1)
146+
editor:select_to(select.x, select.y - 1)
147+
end
130148
end,
131149
["alt_down"] = function()
132-
-- current line information
133-
local line = editor:get_line()
134150
local cursor = editor.cursor
135-
-- insert a new line
136-
editor:insert_line_at(line, cursor.y + 2)
137-
-- delete old copy and reposition cursor
138-
editor:remove_line_at(cursor.y)
139-
-- restore cursor position
140-
editor:move_to(cursor.x, cursor.y + 1)
141-
-- correct indentation level
142-
autoindent:fix_indent()
151+
local select = editor.selection
152+
local single = select.x == cursor.x and select.y == cursor.y
153+
if single then
154+
-- move single line
155+
editor:move_line_down()
156+
autoindent:fix_indent()
157+
else
158+
-- move an entire selection
159+
if cursor.y > select.y then
160+
for line = cursor.y, select.y, -1 do
161+
editor:move_to(cursor.x, line)
162+
editor:move_line_down()
163+
end
164+
else
165+
for line = select.y, cursor.y, -1 do
166+
editor:move_to(cursor.x, line)
167+
editor:move_line_down()
168+
end
169+
end
170+
editor:move_to(cursor.x, cursor.y + 1)
171+
editor:select_to(select.x, select.y + 1)
172+
end
143173
end,
144174
["ctrl_w"] = function()
145175
editor:remove_word()
@@ -309,5 +339,4 @@ syntax:set("deletion", {255, 100, 100}) -- Lists in various markup languages e.g
309339
-- Import plugins (must be at the bottom of this file)
310340
load_plugin("pairs.lua")
311341
load_plugin("autoindent.lua")
312-
--load_plugin("pomodoro.lua")
313-
--load_plugin("update_notification.lua")
342+
load_plugin("quickcomment.lua")

kaolinite/src/document.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl Document {
262262
self.file.insert(idx, st);
263263
// Update cache
264264
let line: String = self.file.line(loc.y).chars().collect();
265-
self.lines[loc.y] = line.trim_end_matches(&['\n', '\r']).to_string();
265+
self.lines[loc.y] = line.trim_end_matches(['\n', '\r']).to_string();
266266
// Update unicode map
267267
let dbl_start = self.dbl_map.shift_insertion(loc, st, self.tab_width);
268268
let tab_start = self.tab_map.shift_insertion(loc, st, self.tab_width);
@@ -341,7 +341,7 @@ impl Document {
341341
self.file.remove(start..end);
342342
// Update cache
343343
let line: String = self.file.line(y).chars().collect();
344-
self.lines[y] = line.trim_end_matches(&['\n', '\r']).to_string();
344+
self.lines[y] = line.trim_end_matches(['\n', '\r']).to_string();
345345
self.old_cursor = self.loc().x;
346346
Ok(())
347347
}
@@ -432,6 +432,36 @@ impl Document {
432432
Ok(())
433433
}
434434

435+
/// Swap a line upwards
436+
/// # Errors
437+
/// When out of bounds
438+
pub fn swap_line_up(&mut self) -> Result<()> {
439+
let cursor = self.char_loc();
440+
let line = self.line(cursor.y).ok_or(Error::OutOfRange)?;
441+
self.insert_line(cursor.y.saturating_sub(1), line)?;
442+
self.delete_line(cursor.y + 1)?;
443+
self.move_to(&Loc {
444+
x: cursor.x,
445+
y: cursor.y.saturating_sub(1),
446+
});
447+
Ok(())
448+
}
449+
450+
/// Swap a line downwards
451+
/// # Errors
452+
/// When out of bounds
453+
pub fn swap_line_down(&mut self) -> Result<()> {
454+
let cursor = self.char_loc();
455+
let line = self.line(cursor.y).ok_or(Error::OutOfRange)?;
456+
self.insert_line(cursor.y + 2, line)?;
457+
self.delete_line(cursor.y)?;
458+
self.move_to(&Loc {
459+
x: cursor.x,
460+
y: cursor.y + 1,
461+
});
462+
Ok(())
463+
}
464+
435465
/// Cancels the current selection
436466
pub fn cancel_selection(&mut self) {
437467
self.cursor.selection_end = self.cursor.loc;
@@ -953,6 +983,8 @@ impl Document {
953983
// Bounds checking
954984
if self.loc().y != y && y <= self.len_lines() {
955985
self.cursor.loc.y = y;
986+
} else if y > self.len_lines() {
987+
self.cursor.loc.y = self.len_lines();
956988
}
957989
// Snap to end of line
958990
self.fix_dangling_cursor();
@@ -1140,7 +1172,7 @@ impl Document {
11401172
self.tab_map.insert(i, tab_map);
11411173
// Cache this line
11421174
self.lines
1143-
.push(line.trim_end_matches(&['\n', '\r']).to_string());
1175+
.push(line.trim_end_matches(['\n', '\r']).to_string());
11441176
}
11451177
// Store new loaded point
11461178
self.info.loaded_to = to;
@@ -1297,17 +1329,21 @@ impl Document {
12971329
self.file.slice(self.selection_range()).to_string()
12981330
}
12991331

1332+
/// Commit a change to the undo management system
13001333
pub fn commit(&mut self) {
13011334
let s = self.take_snapshot();
1335+
self.undo_mgmt.backpatch_cursor(&self.cursor);
13021336
self.undo_mgmt.commit(s);
13031337
}
13041338

1339+
/// Completely reload the file
13051340
pub fn reload_lines(&mut self) {
13061341
let to = std::mem::take(&mut self.info.loaded_to);
13071342
self.lines.clear();
13081343
self.load_to(to);
13091344
}
13101345

1346+
/// Delete the currently selected text
13111347
pub fn remove_selection(&mut self) {
13121348
self.file.remove(self.selection_range());
13131349
self.reload_lines();

kaolinite/src/event.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,11 @@ impl UndoMgmt {
189189
pub fn at_file(&self) -> bool {
190190
self.undo.len() == self.on_disk
191191
}
192+
193+
/// Change the cursor position of the previous snapshot
194+
pub fn backpatch_cursor(&mut self, cursor: &Cursor) {
195+
if let Some(snapshot) = self.undo.last_mut() {
196+
snapshot.cursor = *cursor;
197+
}
198+
}
192199
}

0 commit comments

Comments
 (0)