Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- Comments must be written in English; please use simple English so that non-native English speakers can understand them. If you need to update the documentation, do so in the respective language of each document.
- The goal of the code is to be human-readable and maintainable; use this as the foundation to complete your task.
- Please refer to `CODE_OF_CONDUCT.md` and `CONTRIBUTING.md`; all requirements applicable to human contributors and AI policies apply to you as well.
- Your comment should NOT contain Markdown elements.
3 changes: 3 additions & 0 deletions doc/shortcuts/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
* **Complete** (open/close the completion popup): `Alt + /`.
* **Toggle auto completion**: `Ctrl + C` `Alt + L`.
* **Apply autofix**: `Ctrl + C` `A`.
* **Search forward / backward**: `Ctrl + S` / `Ctrl + R`. (`Enter` to stop, `Ctrl + G` to go back.)
* **Query replace**: `Alt + %`. Then answer at each match: `Y`/`Space` replace, `N` skip, `!` replace all, `.` replace and stop, `Q` stop.
* **Go to line**: `Alt + G` `G` (or `Alt + G` `Alt + G`).
3 changes: 3 additions & 0 deletions doc/shortcuts/shortcuts.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
* **补全列表**: `Alt + /`.
* **自动补全**: `Ctrl + C` `Alt + L`.
* **自动修复**: `Ctrl + C` `A`.
* **向前 / 向后查找**: `Ctrl + S` / `Ctrl + R`. (`Enter`结束,`Ctrl + G`回到起点)
* **逐个替换**: `Alt + %`. (`Y`/`空格`替换,`N`跳过,`!`全部替换,`.`替换后结束,`Q`结束)
* **跳转到行**: `Alt + G` `G` (或`Alt + G` `Alt + G`).
13 changes: 12 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub(crate) struct App {
pub(crate) cpp_checks: crate::buffers::cpp_checks::Checks,
pub(crate) completion: crate::buffers::completion::Completion,
pub(crate) quick_fix: crate::buffers::fixes::QuickFix,
pub(crate) search: crate::buffers::search::Search,
pub(crate) goto_line: crate::buffers::goto_line::GotoLine,
// Draw icons from a Nerd Font (WINDOW menu).
pub(crate) nerd_font: bool,
}

// Implementation of the app struct
Expand Down Expand Up @@ -87,6 +91,7 @@ impl App {
let prefix = match (self.ctrl_x_wait_flag, self.ctrl_c_wait_flag) {
(true, _) => "C-x ",
(_, true) => "C-c ",
_ if self.goto_line.after_prefix() => "M-g ",
_ => "",
};
self.buffer_command = crate::utils::keys::shortcut_label(key, !prefix.is_empty())
Expand Down Expand Up @@ -159,7 +164,13 @@ impl App {
return;
}

if !self.ctrl_x_wait_flag && self.menu.active.is_none() && self.handle_completion_key(key) {
// Search and replace see keys before completion.
if !self.ctrl_x_wait_flag
&& self.menu.active.is_none()
&& (self.handle_search_key(key)
|| self.handle_goto_line_key(key)
|| self.handle_completion_key(key))
{
return;
}

Expand Down
15 changes: 13 additions & 2 deletions src/buffers/diagnostics/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// You should have received a copy of the GNU General Public License along with this software. If
// not, see <https://www.gnu.org/licenses/>.

use super::color;
use super::{color, nerd_icon};
use crate::{app::App, lsp::Diagnostic};
use ratatui::{
Frame,
Expand Down Expand Up @@ -57,7 +57,12 @@ impl App {
let Some(worst) = on_line.iter().map(|d| d.severity).min() else {
continue;
};
buf[(area.left(), y)].set_symbol("●").set_fg(color(worst));
let mark = if self.nerd_font {
nerd_icon(worst)
} else {
"●"
};
buf[(area.left(), y)].set_symbol(mark).set_fg(color(worst));

// Underline marked chars, up to the first cell after the text of the line.
let mut end_x = None;
Expand Down Expand Up @@ -148,5 +153,11 @@ mod tests {
assert!(row(y + 2).contains("z unused 'z'"));
assert_eq!(screen[(area.left(), y + 3)].symbol(), " ");
assert!(!row(y + 3).contains("unused"));

app.nerd_font = true;
terminal.draw(|frame| app.draw(frame)).unwrap();
let screen = terminal.backend().buffer();
assert_eq!(screen[(area.left(), y)].symbol(), "\u{f057}");
assert_eq!(screen[(area.left(), y + 2)].symbol(), "\u{f071}");
}
}
9 changes: 9 additions & 0 deletions src/buffers/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ impl App {
}

// Coloring config for the status bar.
pub(super) fn nerd_icon(severity: Severity) -> &'static str {
match severity {
Severity::Error => "\u{f057}",
Severity::Warning => "\u{f071}",
Severity::Information => "\u{f05a}",
Severity::Hint => "\u{f0eb}",
}
}

pub(super) fn color(severity: Severity) -> Color {
match severity {
Severity::Error => Color::LightRed,
Expand Down
32 changes: 26 additions & 6 deletions src/buffers/editor_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// You should have received a copy of the GNU General Public License along with this software. If
// not, see <https://www.gnu.org/licenses/>.

use super::{diagnostics::color, menu::LIGHT_BLUE};
use super::{
diagnostics::{color, nerd_icon},
menu::LIGHT_BLUE,
};
use crate::lsp::Severity;
use ratatui::{
Frame,
Expand Down Expand Up @@ -57,12 +60,21 @@ fn labels(editor: &Editor) -> (String, String) {
}

// The error/warning indicator.
fn problem_spans((errors, warnings): (usize, usize)) -> [Span<'static>; 4] {
// In Nerd Font mode the letters are replaced with the severity icons.
fn problem_spans((errors, warnings): (usize, usize), nerd_font: bool) -> [Span<'static>; 4] {
let label = |severity, letter, count| {
let span = if nerd_font {
format!("{} {count}", nerd_icon(severity))
} else {
format!("{letter}: {count}")
};
Span::styled(span, color(severity))
};
let separator = Span::styled(" · ", Style::default().fg(LIGHT_BLUE));
[
Span::styled(format!("E: {errors}"), color(Severity::Error)),
label(Severity::Error, 'E', errors),
separator.clone(),
Span::styled(format!("W: {warnings}"), color(Severity::Warning)),
label(Severity::Warning, 'W', warnings),
separator,
]
}
Expand All @@ -71,6 +83,7 @@ fn problem_spans((errors, warnings): (usize, usize)) -> [Span<'static>; 4] {
pub(super) fn draw(
editor: &Editor,
problems: (usize, usize),
nerd_font: bool,
frame: &mut Frame,
area: Rect,
border_area: Rect,
Expand All @@ -92,7 +105,7 @@ pub(super) fn draw(

let area = Rect::new(area.x, area.y + 1, area.width, 1);
let (left, right) = labels(editor);
let mut right_line = Line::from(problem_spans(problems).to_vec());
let mut right_line = Line::from(problem_spans(problems, nerd_font).to_vec());
right_line.push_span(right);

let right_width = u16::try_from(right_line.width()).unwrap_or(u16::MAX);
Expand Down Expand Up @@ -137,12 +150,19 @@ mod tests {

#[test]
fn problems_show_errors_in_red_and_warnings_in_yellow() {
let spans = problem_spans((2, 11));
let spans = problem_spans((2, 11), false);
let text: String = spans.iter().map(|span| span.content.as_ref()).collect();
assert_eq!(text, "E: 2 · W: 11 · ");
assert_eq!(spans[0].style.fg, Some(Color::LightRed));
assert_eq!(spans[1].style.fg, Some(LIGHT_BLUE));
assert_eq!(spans[2].style.fg, Some(Color::Yellow));

// Nerd Font mode puts the icons in place of the letters, in the same colors.
let spans = problem_spans((2, 11), true);
let text: String = spans.iter().map(|span| span.content.as_ref()).collect();
assert_eq!(text, "\u{f057} 2 · \u{f071} 11 · ");
assert_eq!(spans[0].style.fg, Some(Color::LightRed));
assert_eq!(spans[2].style.fg, Some(Color::Yellow));
}

#[test]
Expand Down
Loading
Loading