Skip to content
Open
Changes from 3 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
31a7f70
added partial solution
razvanrus2003 Jan 20, 2024
f63bcdb
better highlight length getter (using unicode_width)
razvanrus2003 Jan 20, 2024
7df0d7a
finnished coding style
razvanrus2003 Jan 20, 2024
755da5a
fixed warnings
razvanrus2003 Jan 21, 2024
57268a2
Lines optimization (#280)
razvanrus2003 Jan 22, 2024
c919b27
add auzkok as contributor for syntax-highlighting (#278)
ilai-deutel Jan 22, 2024
991dc7b
[CI] Fail on Clippy error (#283)
ilai-deutel Jan 22, 2024
945b3e6
Merge branch 'master' into utf8_prompts
ilai-deutel Jan 22, 2024
8966c46
[CI] Actually fail on Clippy error (#284)
ilai-deutel Jan 22, 2024
1eeaab1
Bump libc from 0.2.152 to 0.2.153 (#286)
dependabot[bot] Feb 18, 2024
596945d
Bump tempfile from 3.9.0 to 3.10.0 (#289)
dependabot[bot] Feb 18, 2024
a22a3bd
Bump tempfile from 3.9.0 to 3.10.0 in /fuzz (#288)
dependabot[bot] Feb 18, 2024
3d8e309
Bump tempfile from 3.10.0 to 3.10.1 in /fuzz (#290)
dependabot[bot] Sep 22, 2024
230184c
Bump tempfile from 3.10.0 to 3.10.1 (#291)
dependabot[bot] Sep 22, 2024
18a314d
Bump unicode-width from 0.1.11 to 0.1.12 (#294)
dependabot[bot] Sep 22, 2024
42b1ef2
Bump winapi-util from 0.1.6 to 0.1.8 (#295)
dependabot[bot] Sep 22, 2024
a1573de
Bump libc from 0.2.153 to 0.2.155 (#297)
dependabot[bot] Sep 22, 2024
e08fcc4
Bump libc from 0.2.155 to 0.2.158 (#301)
dependabot[bot] Sep 23, 2024
306b115
Bump tempfile from 3.10.1 to 3.12.0 in /fuzz (#299)
dependabot[bot] Sep 23, 2024
8c607d6
Bump winapi-util from 0.1.8 to 0.1.9 (#302)
dependabot[bot] Sep 23, 2024
d0b3aee
Bump libc from 0.2.158 to 0.2.159 (#303)
dependabot[bot] Oct 2, 2024
132baa1
Bump tempfile from 3.12.0 to 3.13.0 in /fuzz (#304)
dependabot[bot] Oct 2, 2024
44bf29a
Bump MSRV to Rust 1.65.0 (#306)
ilai-deutel Oct 13, 2024
da51e37
Bump serial_test from 3.0.0 to 3.1.1 (#293)
dependabot[bot] Oct 13, 2024
06bba14
But MSRV to 1.66.0 (#307)
ilai-deutel Oct 13, 2024
4e23384
Bump unicode-width from 0.1.12 to 0.2.0 (#300)
dependabot[bot] Oct 14, 2024
6ebc9ea
[CI] Migrate WASI targets (#316)
ilai-deutel Nov 13, 2024
d14a358
[CI] Upgrade code coverage generation (#317)
ilai-deutel Nov 13, 2024
dba0a6e
Bump tempfile from 3.10.1 to 3.13.0 (#309)
dependabot[bot] Nov 13, 2024
03e18a3
Bump tempfile from 3.13.0 to 3.14.0 in /fuzz (#315)
dependabot[bot] Nov 13, 2024
6d8a48d
Bump libfuzzer-sys from 0.4.7 to 0.4.8 in /fuzz (#314)
dependabot[bot] Nov 13, 2024
7261e69
Bump libc from 0.2.159 to 0.2.162 (#313)
dependabot[bot] Nov 13, 2024
40e91ef
Bump serial_test from 3.1.1 to 3.2.0 (#312)
dependabot[bot] Nov 13, 2024
591aa3a
Use alternate screen (#310)
malbarbo Nov 13, 2024
7684d28
[CI] Upgrade action versions (#319)
ilai-deutel Nov 13, 2024
a616ced
add Jan9103 as a contributor for code (#318)
allcontributors[bot] Nov 13, 2024
657cb4d
Update rusfmt config and fix associated clippy errors (#321)
ilai-deutel Nov 13, 2024
f989f6f
Update README.md - HelloGitHub claim
ilai-deutel Nov 13, 2024
5297230
add joshka as a contributor for infra (#324)
allcontributors[bot] Nov 13, 2024
e33d26f
fix: crash when opening a new file (#287)
Nov 14, 2024
cb13bce
[CI] Configure secret token for reviewdog (#332)
ilai-deutel Nov 14, 2024
be558cf
[Clippy] Check in config, update CI (#333)
ilai-deutel Nov 14, 2024
cce6e93
Combine mod xdg with cfg(any) (LOC -= 1) (#335)
ilai-deutel Nov 14, 2024
1422e1e
[Clippy] Add nursery-level warnings, fix issues found (#334)
ilai-deutel Nov 15, 2024
4f0d79c
Fix formatting and Clippy workflows outside of pull requests (#336)
ilai-deutel Nov 15, 2024
b7167e7
Replace Key::Page(PageKey) with Key::Page{Up,Down} (#331)
joshka Nov 15, 2024
cc7ec3a
add joshka as a contributor for code (#337)
allcontributors[bot] Nov 15, 2024
e02145f
Add vscode settings for using nightly rustfmt (#329)
joshka Nov 15, 2024
d3a4843
[CI] Update security workflows, add cargo-deny, deprecate cargo-audit…
ilai-deutel Nov 17, 2024
50944c6
Fix config parsing with invalid durations (#340)
ilai-deutel Nov 18, 2024
aa31bf9
Bump MSRV to 1.80 (#343)
ilai-deutel Nov 18, 2024
b5dcbf5
[Tests] Remove dependency on serial_test, use Mutex instead (#341)
ilai-deutel Nov 18, 2024
c24668b
Fix markdownlint errors in README.md
ilai-deutel Nov 18, 2024
cf2dc81
Delete .github/workflows/devskim.yml
ilai-deutel Nov 18, 2024
2b9aa5d
Add weekly sanitizer run to CI (#342)
ilai-deutel Nov 18, 2024
2a5840e
[CI] Temporarily stop using mbrobbel/rustfmt-check
ilai-deutel Nov 19, 2024
edcba19
Use module paths instead of conditional module includes for sys modul…
joshka Nov 19, 2024
d9db901
Replace count_loc.sh with xtask (#328)
joshka Nov 20, 2024
5eff635
[xtask] Add more info to Cargo.toml (#344)
ilai-deutel Nov 24, 2024
382b422
Fix lint config for main crate
ilai-deutel Nov 24, 2024
7456225
Remove obsolete TODO
ilai-deutel Nov 26, 2024
7bedad6
Add more lints to check and clippy configuration (#345)
ilai-deutel Nov 26, 2024
a03e7c2
feat: enable LTO (#346)
zamazan4ik Nov 27, 2024
9f0cf2c
add zamazan4ik as a contributor for infra (#347)
allcontributors[bot] Nov 27, 2024
1628b51
Adding test for home + end keys (#311)
BanuAdrian Nov 27, 2024
fa5b32a
add BanuAdrian as a contributor for test (#320)
allcontributors[bot] Nov 27, 2024
0748dbe
Merge branch 'master' into utf8_prompts
ilai-deutel Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use std::fmt::{Display, Write as _};
use std::io::{self, BufRead, BufReader, ErrorKind, Read, Seek, Write};
use std::iter::{self, repeat, successors};
use std::{fs::File, path::Path, process::Command, thread, time::Instant};
use std::{cell::RefCell, fs::File, path::Path, process::Command, thread, time::Instant};

use unicode_width::UnicodeWidthStr;

use crate::row::{HlState, Row};
use crate::{ansi_escape::*, syntax::Conf as SyntaxConf, sys, terminal, Config, Error};
Expand All @@ -28,9 +30,9 @@ const HELP_MESSAGE: &str =

/// `set_status!` sets a formatted status message for the editor.
/// Example usage: `set_status!(editor, "{} written to {}", file_size, file_name)`
macro_rules! set_status {
($editor:expr, $($arg:expr),*) => ($editor.status_msg = Some(StatusMessage::new(format!($($arg),*))))
}
macro_rules! set_status { ($editor:expr, $($arg:expr),*) => ($editor.status_msg = Some(StatusMessage::new(format!($($arg),*)))) }
// `width!` returns the display width of a string, plus one for the cursor
fn dsp_width(msg: &String) -> usize { UnicodeWidthStr::width(msg.as_str()) + 1 }

/// Enum of input keys
enum Key {
Expand Down Expand Up @@ -593,7 +595,7 @@ impl Editor {
(self.rx() - self.cursor.coff + 1 + self.ln_pad, self.cursor.y - self.cursor.roff + 1)
} else {
// If in prompt mode, position the cursor on the prompt line at the end of the line.
(self.status_msg.as_ref().map_or(0, |sm| sm.msg.len() + 1), self.screen_rows + 2)
(self.status_msg.as_ref().map_or(0, |s| dsp_width(&s.msg)), self.screen_rows + 2)
};
// Finally, print `buffer` and move the cursor
print!("{buffer}\x1b[{cursor_y};{cursor_x}H{SHOW_CURSOR}");
Expand Down Expand Up @@ -678,7 +680,7 @@ impl Editor {
// will be updated in self.cursor.scroll() so that the result is visible
(self.cursor.x, self.cursor.y, self.cursor.coff) = (cx, current, 0);
let rx = row.cx2rx[cx];
row.match_segment = Some(rx..rx + query.len());
row.match_segment = Some(rx..rx + UnicodeWidthStr::width(query));
return Some(current);
}
}
Expand Down Expand Up @@ -837,18 +839,22 @@ enum PromptState {
Cancelled,
}

thread_local! (static CHARACTER: RefCell<Vec<u8>> = {let cache = Vec::new(); RefCell::new(cache)});
/// Process a prompt keypress event and return the new state for the prompt.
fn process_prompt_keypress(mut buffer: String, key: &Key) -> PromptState {
match key {
Key::Char(b'\r') => return PromptState::Completed(buffer),
Key::Escape | Key::Char(EXIT) => return PromptState::Cancelled,
Key::Char(BACKSPACE | DELETE_BIS) => {
buffer.pop();
}
Key::Char(BACKSPACE | DELETE_BIS) => _ = buffer.pop(),
Key::Char(c @ 0..=126) if !c.is_ascii_control() => buffer.push(*c as char),
Key::Char(c @ 128..=255) => CHARACTER.with(|cache| cache.borrow_mut().push(*c)),
// No-op
_ => (),
}
let character = CHARACTER.with(|cache| String::from_utf8(cache.borrow_mut().clone()));
character.clone().map_or((), |c| buffer.push_str(c.as_str()));
character.map_or((), |_| CHARACTER.with(|cache| cache.borrow_mut().clear()));

PromptState::Active(buffer)
}

Expand Down